WPF ProgressBar doesn't update?
I am trying to update my progressbar by using data bindings. The XAML file contains the progressbar:
<ProgressBar Height="23" Name="progressBar" VerticalAlignment="Bottom" Margin="207,444,0,0" Minimum="0" Maximum="{Binding ProgressBarMax}" Value="{Binding ProgressBarValue}" />
My relevant C# class contains the getter & setter:
private int progressBarMax;
public int ProgressBarMax
{
get
{
if (this.progressBarMax == 0)
this.progressBarMax = 1;
return this.progressBarMax;
}
set
{
this.progressBarMax = value;
}
}
private int progressBarValue;
public int ProgressBarValue
{
get
{
return progressBarValue;
}
set
{
progressBarValue = value;
}
}
In my "update" method the maximum is being set. For exampl开发者_高级运维e like this.progressBarMax = 100;
. In a loop the progressbar value is getting the value += 1. To see the updates I used Application.DoEvents(), later I will implement threads. The data binding has to be correct, because I have other components that work fine.
So why doesn't my progressbar update?
Thank you for your help.
You need to implement a way to let your ProgressBar be notified whenever ProgressBarValue changes. Have a look at the INotifyPropertyChanged interface.
What about INotifyPropertyChanged to make your UI controls detect updated values?
//daniel
I was hoping to actually add a comment to the original post, but I will have to settle for a question regarding the original entered through the answer text bax. Can you post your code as a unit? That is, all the code you needed to add to complete the binding? I am having trouble getting all the pieces together to do a data binding for my maximum and value for my progress bar and it may help quite a bit.
I found the mistake in my code. Unfortunately I changed my private members, not the public properties. So when using this.ProgressBarValue += 1;
instead of this.progressBarValue += 1;
everything works fine.
精彩评论