0

次のように、INotifyPropertyChanged を実装するクラスのプロパティにバインドされた GridView を持つ ListView があります。

<ListView Name="SubscriptionView" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" ItemsSource="{Binding Path=Subscriptions}">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="24" CellTemplate="{StaticResource IncludeSubscriptionTemplate}"/>
            <GridViewColumn Width="150" DisplayMemberBinding="{Binding Path=Name}" Header="Subscription"/>
            <GridViewColumn Width="75" DisplayMemberBinding="{Binding Path=RecordsWritten}" Header="Records"/>
            <GridViewColumn Width="Auto" CellTemplate="{StaticResource FilenameTemplate}"/>
        </GridView>
    </ListView.View>
</ListView>

クラスは次のようになります。

public class Subscription : INotifyPropertyChanged
{
    public int RecordsWritten
    {
        get
        {
            return _records;
        }
        set
        {
            _records = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("RecordsWritten"));
        }
    }
    private int _records;

    ...
}

そこで、BackgroundWorker を起動してレコードの書き込みを開始し、RecordsWritten プロパティを更新して、UI で値が変更されることを期待しますが、変更されません。実際、Subscription オブジェクトの PropertyChanged の値は null です。WPF は INotifyPropertyChanged を実装するデータ オブジェクトの PropertyChanged イベントをサブスクライブするはずだと思っていたので、これは難問です。ここで何か間違ったことをしていますか?

4

1 に答える 1

2

問題を理解しました。「サブスクリプション」リストは、LINQ クエリからのものでした。そのクエリの最後に .ToList() を追加すると、UI が適切に更新され始めました。

于 2010-04-07T15:16:39.823 に答える