C#接口INotifyPropertyChanged使用方法

  public class ViewModelBase : INotifyPropertyChanged

  {

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(string propertyName)

  {

  if (this.PropertyChanged != null)

  this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

  }

  }

  public class MainViewModel : ViewModelBase

  {

  private string name;

  private string code;

  public string Name

  {

  get { return name; }

  set { name = value; OnPropertyChanged("Name"); }

  }

  public string Code

  {

  get { return code; }

  set { code = value; OnPropertyChanged("Code"); }

  }

  }