1. 程式人生 > >WPF 實現INotifyPropertyChanged .Net Framework 4.5

WPF 實現INotifyPropertyChanged .Net Framework 4.5

hang nta not void one using style call str

  自己動手寫了一個基類來實現INotifyPropertyChanged接口,以後可以直接使用。

 1 using System.ComponentModel;
 2 using System.Runtime.CompilerServices;
 3 
 4 public abstract class NotifyPropertyBase: INotifyPropertyChanged
 5 {
 6      public event PropertyChangedEventHandler PropertyChenged;
 7 
 8      protected void
SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null) 9 { 10 if (object.Equals(storage, value)) return; 11 storage = value; 12 this.OnPropertyChanged(propertyName); 13 } 14 15 protected void OnPropertyChanged([CallerMemberName] string
propertyName = null) 16 { 17 if (this.PropertyChanged != null) 18 { 19 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 20 } 21 } 22 }

WPF 實現INotifyPropertyChanged .Net Framework 4.5