Creating a strongly typed reactive wrapper to INotifyPropertyChanged
• Richard Szalay
Practical Ugliness
INotifyPropertyChanged is a great, built-in, way for property change notification to work in the WPF/Silverlight world. Attempting to use it from staticly typed code, however, gets messy:
Things get even worse when we try to make this reactive:
An Expressive Solution
The extension method below allows you to specify the property you want to watch using an Expression<Func>, keeping things nice for the compiler:
Edit: Updated once it was tested (and simplified)
GetPropertyValues returns an IObservable of the values of the property as they change, starting with the current value.
You can then use it like so:
I hope this method can be as useful to you as it has been to me.