【问题标题】:INotifyPropertyChanged on a property that contains an i list包含 i 列表的属性上的 INotifyPropertyChanged
【发布时间】:2009-05-12 08:38:12
【问题描述】:

您好,我在 myClass 中使用此代码来更改我的 wpf 应用程序中的内容

      public event PropertyChangedEventHandler PropertyChanged;
  protected void Notify(string propertyName)
  {
     if (this.PropertyChanged != null)
     {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     }
  }

每次我更改 myClass 中的属性时,它都会更改我在我的应用程序中拥有的标签。

 <Label Content="{Binding Category}" Padding="7,0,0,0" />

这工作得很好,但在 myClass 我有一个属性包含另一个类文章的 ilist

private IList<Article> m_articles = new List<Article>();

现在我的问题是,Notify 方法不会更新我的 Ilist 中的内容,我是否可以通过 ilist 和视图使其更新。如果 myclass 是字符串或 int,则 myclass 中的所有属性都可以正常工作,但是当它是 Ilist 时,它不会更新。希望你们明白我的意思是我的英语很糟糕。 感谢您的帮助

这里是xaml中的代码

                            <ListBox Name="ArtInfo" ItemsSource="{Binding Path=Articles}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Label Content="{Binding Artnr}" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>

{Binding Path=Articles}

【问题讨论】:

    标签: wpf inotifypropertychanged


    【解决方案1】:

    你应该使用 ObservableCollection

    而不是 List

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      • 2013-08-12
      • 2019-04-04
      • 2021-08-22
      相关资源
      最近更新 更多