If the class I want to add a property is a DependencyObject
, I generally add a DependencyProperty
. If the class is a POCO (plain old clr objects), then I implement INotifyPropertyChanged
.
In generall, all my business objects are POCOs and therefore I use INotifyPropertyChanged
. In the WPF world, I mostly use DependencyObjects (view models, custom controls, UserControls...) and therefore they are DependencyProperties. An exception are ViewModels representing items (to be used as items in an items source). In this case I think DependencyProperties are not very practical (Because Equals() and GetHashCode() of DependencyObjects are sealed and DependencyObject
is thread-dependent).
If your class already is a DependencyObject
, using DependencyProperties may give you some nice advantages: You don't have to back every value, a powerfull inheritance system, default-values, property changed callbacks per property, value coercion ... (I like DependencyProperties probably more than other people them like :)
Conclusion:
Based on the title of your question: How to get notified when something changes in a WPF window?, my way would be to add a DependencyProperty
and not a clr-property because the Window is a DependencyObject
. By the way, Visual Studio has a nice Snippet to create DependencyProperties.