[英]My ProgressBar won't update
No matter what I do my progress bar won't update. 不管我做什么,进度条都不会更新。
My XAML: 我的XAML:
<Grid Height="25">
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Setter Property="Visibility" Value="Collapsed" />
<!--EDITING HERE-->
<Style.Triggers>
<DataTrigger Binding="{Binding Path=PleaseWaitDialog, Mode=OneWay}"
Value="true">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<ProgressBar Value="{Binding Path=Percent}" />
</Grid>
Then in the ViewModel: 然后在ViewModel中:
private double _percent;
public double Percent
{
get { return _percent; }
set
{
SetProperty("Percent", () => false, () => _percent = value);
}
}
Then I set the value with: 然后我用以下方法设置值:
_profileService.ApplyProfile(_data, (s, d) => UpdateApplyProgress(s, d, pleaseWaitVm));
and the update is: 更新是:
private void UpdateApplyProgress(string message, double percent, CUDialogVM dialogVm)
{
//Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(() => dialogVm.Progress = percent));
dialogVm.Percent = percent;
}
I tried it with the dispatcher and it still didn't work. 我曾与调度员尝试过,但仍然无法正常工作。 I have also tried setting the value explicitly and nothing.
我也尝试过显式设置值,什么也没有。 Also I have checked in the debugger and the viewModel's Percent property is being set and the PropertyChangedEvent is being fired.
另外,我已经签入调试器,并设置了viewModel的Percent属性,并触发了PropertyChangedEvent。
The SetPropertyMethod: SetPropertyMethod:
protected bool SetProperty<T>(string propertyName, Func<bool> areEqual, Func<T> setValue)
{
VerifyPropertyName(propertyName);
if (!areEqual.Invoke())
{
setValue.Invoke();
RaisePropertyChanged(propertyName);
IsChanged = true;
}
return true;
}
As per HB below my binding now is: 根据我下面的绑定下面的HB:
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Percent}" />
The ProgressBar.Minimum
and Maximum
defaults are 0
and 1
, are your values in that range? ProgressBar.Minimum
和Maximum
默认0
和1
,您的值在该范围内吗? If not change those properties accordingly. 如果没有,请相应地更改这些属性。
Try that in your XAML: 在您的XAML中尝试:
<ProgressBar Value="{Binding Path=Percent, UpdateSourceTrigger=PropertyChanged}" />
Moreover, the ProgressBar
values have to be between 0 and 100! 此外,
ProgressBar
值必须在0到100之间!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.