无论我做什么,我的进度条都不会更新。
我的 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>
然后在 ViewModel 中:
private double _percent;
public double Percent
{
get { return _percent; }
set
{
SetProperty("Percent", () => false, () => _percent = value);
}
}
然后我设置值:
_profileService.ApplyProfile(_data, (s, d) => UpdateApplyProgress(s, d, pleaseWaitVm));
更新是:
private void UpdateApplyProgress(string message, double percent, CUDialogVM dialogVm)
{
//Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(() => dialogVm.Progress = percent));
dialogVm.Percent = percent;
}
我用调度员试了一下,还是不行。我也尝试过明确设置值,但什么也没有。我还检查了调试器,并且正在设置 viewModel 的 Percent 属性,并且正在触发 PropertyChangedEvent。
设置属性方法:
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;
}
根据下面的 HB,我现在的绑定是:
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Percent}" />