Annoyed with INotifyPropertyChanged?
Have you ever been annoyed with having to implement the cumbersome plumbing required for INotifyPropertyChanged ? Well, I have. So I tried to find a way to make authoring bindable objects better. The typical example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class Contact : INotifyPropertyChanged { private string _firstName; public string FirstName { get { return _firstName; } set { if (!Equals(_firstName, value)) { _firstName = value; OnPropertyChanged("FirstName"); } } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } |
As you can see, it is quite verbose. The event and OnPropertyChanged() method need to be implemented for each […]