我试图绑定的ObservableCollection
public class ProgressInfo : BindableBase, IProgress<Tuple<string, int>>
{
public ProgressInfo()
{
Message = "start";
ProgressBarValue = 50;
}
private string _message;
public string Message
{
get { return _message; }
set { _message = value; OnPropertyChanged(() => Message); }
}
private int _progressBarValue;
public int ProgressBarValue
{
get { return _progressBarValue; }
set { _progressBarValue = value; OnPropertyChanged(() => ProgressBarValue); }
}
public void Report(Tuple<string, int> value)
{
this.Message = value.Item1;
this.ProgressBarValue = value.Item2;
}
}
带有自定义内容的WPF Toolkit BusyIndicator
<xctk:BusyIndicator DisplayAfter="0" IsBusy="{Binding IsBusy, Mode=OneWay}" >
<xctk:BusyIndicator.BusyContentTemplate>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="{x:Static lang:Resources.TRWAIMPORT}" FontWeight="Bold" HorizontalAlignment="Center"/>
<ItemsControl ItemsSource="{Binding ProgressInfos, UpdateSourceTrigger=PropertyChanged}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="{Binding ProgressInfo.Message, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay }"/>
<ProgressBar Value="{Binding Path=ProgressInfo.ProgressBarValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Height="15"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</xctk:BusyIndicator.BusyContentTemplate>
<xctk:BusyIndicator.ProgressBarStyle>
<Style TargetType="ProgressBar">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</xctk:BusyIndicator.ProgressBarStyle>
此外,我将 ObervableCollection 中的对象传递给我的任务,以便他们通过Report方法更改其属性。
但由于某种原因 BusyIndicator 永远不会使用新值更新, ObservableCollection 似乎总是为空( ItemsControl 不会产生任何项目)
我做错了什么?这种方法适用于任何其他控件,但 BusyIndicator 似乎无法正确使用