14 January 2011

.NET - Implementing INotifyPropertyChanged

To implement the INotifyPropertyChanged interface on a business object:
  • Implement the interface System.ComponentModel.INotifyPropertyChanged,
  • Add a method like this:
    private void NotifyPropertyChanged([CallerMemberName]string propertyName = null) =>
      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    
  • Use this method in every setter that must notify:
    NotifyPropertyChanged();

No comments:

Post a Comment