I've been using the following bit of code in a cookie cutter fashion, across dozens of classes
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
All of these classes implement INotifyPropertyChanged
. To silence my DRY alarms, lately I've been refactoring these classes to inherit my base class PropertyNotifier
whose only purpose is to provide NotifyPropertyChanged
for classes that inherit from it -- which are the dozens of ViewModel classes in my huge project.
It feels lazy and a bit dirty. Am I hurting performance or breaking good design practices? I figure if change notification was supposed to be this easy, there would be a base class already in the WPF framework that does what my PropertyNotifier
class does.
Note that, for a lot of reasons, I've been having performance issues with my UI responsivity -- mostly due to a large number of controls. So I'm looking to trim the fat wherever I can. Any ideas?