2010-04-07 54 views
0

我有一个绑定到实现INotifyPropertyChanged一类的属性一个GridView一个ListView,像这样:GridViewColumn不订阅PropertyChanged事件在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事件。我在这里做错了什么?

回答

2

找出问题所在。 “订阅”列表来自LINQ查询。当我将.ToList()添加到该查询的末尾时,UI开始正确更新。