Today I’d like to share with you one of my most valued base classes when developing a WPF or WinRT application. Given that WPF applications are intrinsically designed to work well with the MVVM pattern (or perhaps the other way around) it should come as no surprise that every project that implements this pattern has some implementation of the INotifyPropertyChanged interface. I’ve seen a few different variations (all generally very simple) and, in this article, I’d like to present my latest iteration on this crucial base class. Let’s first start by identifying the problems we are trying to solve.
- We need an implementation of the INotifyPropertyChanged interface to allow for data binding
- We need some safe and convenient syntax for calling the event handler for PropertyChanged
- We need to make this call thread safe
- We need to reduce the memory footprint of this call
- *BONUS* Can we factor a pattern out of our code?