问题:当前ListBox Items 绑定 集合数据源ListA时候;ListA集合数据源中存在另外一个集合ListB,当更改或往ListB集合中添加数据的时候,通知改变?
实体类继承 INotifyCollectionChanged 即可实现:
BaseViewModel:
public class BaseViewModel : INotifyPropertyChanged, INotifyCollectionChanged, IDisposable { public event PropertyChangedEventHandler PropertyChanged; public event NotifyCollectionChangedEventHandler CollectionChanged; public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (CollectionChanged != null) { CollectionChanged(this, e); } } public void Dispose() { this.OnDispose(); } protected void OnDispose() { } public void OnCollectionChanged() { } }