1

我试图绑定一个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 BusyIndi​​cator

  <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 方法更改它们的属性。

但是由于某种原因,BusyIndi​​cator永远不会用新值更新,并且ObservableCollection似乎总是为空(ItemsControl不产生任何项目)

我究竟做错了什么 ?这种方法适用于任何其他控件,但BusyIndi​​cator似乎不正确

4

0 回答 0