[英]WPF ProgressBar doesn't update?
I am trying to update my progressbar by using data bindings. 我试图通过使用数据绑定来更新我的进度条。 The XAML file contains the progressbar:
XAML文件包含进度条:
<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: 我的相关C#类包含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 example like
this.progressBarMax = 100;
比如像
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.
在循环中,进度条值获取值+ = 1.要查看我使用Application.DoEvents()的更新,稍后我将实现线程。 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. 谢谢您的帮助。
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. 我本来希望在原帖中添加评论,但是我将不得不通过答案文本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.
我无法将所有部分组合在一起,为我的进度条的最大值和值进行数据绑定,这可能会有所帮助。
You need to implement a way to let your ProgressBar be notified whenever ProgressBarValue changes. 您需要实现一种方法,以便在ProgressBarValue更改时通知ProgressBar。 Have a look at the INotifyPropertyChanged interface.
看看INotifyPropertyChanged界面。
What about INotifyPropertyChanged to make your UI controls detect updated values? 那么INotifyPropertyChanged会让你的UI控件检测到更新的值?
//daniel //丹尼尔
I found the mistake in my code. 我在代码中发现了错误。 Unfortunately I changed my private members, not the public properties.
不幸的是,我改变了我的私人会员,而不是公共财产。 So when using
this.ProgressBarValue += 1;
所以当使用
this.ProgressBarValue += 1;
instead of this.progressBarValue += 1;
而不是
this.progressBarValue += 1;
everything works fine. 一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.