WPF INotifyPropertyChanged
public class OrderModel:INotifyPropertyChanged { public string _oderID; public string OrderID; { get { return _orderID; } set { if(_oderID==value) return; _orderID=value; NotifyPropertyChanged("OrderID"); } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string propertyname) { if(PropertyChanged!=null) { PropertyChanged(this,new PropertyChangedEventArgs(propertyname)); } } }
集合或者属性的改变是需要通知UI,UI才会发生变化的
1.集合的通知接口:INotifyCollectionChanged
2.属性的通知接口:INotifyPropertyChanged
ObervableCollection实现了INotifyCollectionChanged接口,List没有实现