INotifyPropertyChanged vs. DependencyProperty in ViewModel INotifyPropertyChanged vs. DependencyProperty in ViewModel wpf wpf

INotifyPropertyChanged vs. DependencyProperty in ViewModel


Kent wrote an interesting blog about this topic: View Models: POCOs versus DependencyObjects.

Short summary:

  1. DependencyObjects are not marked asserializable
  2. The DependencyObject class overrides and seals the Equals() andGetHashCode() methods
  3. A DependencyObject has thread affinity – it can only be accessedon the thread on which it wascreated

I prefer the POCO approach. A base class for PresentationModel (aka ViewModel) which implements INotifyPropertyChanged interface can be found here: http://compositeextensions.codeplex.com


According to the WPF performance guide, DependencyObjects definitely perform better than POCOs that implement INotifyPropertyChanged:

http://msdn.microsoft.com/en-us/library/bb613546.aspx


The choice is totally based on your business logic and UI abstraction level. If you dont want a good separation then DP will work for you.

DependencyProperties will be applicable mainly at the VisualElements level so it won't be good idea if we create lot of DPs for each of our business requirements. Also there is a greater cost for DP than a INotifyPropertyChanged. When you design a WPF/Silverlight try to design UI and ViewModel totally separate so that at any point of time we can change the Layout and UI controls (Based on theme and Styles)

Refer this post also - https://stackoverflow.com/questions/275098/what-applications-could-i-study-to-understand-datamodel-view-viewmodel . The link has a lot of reference to Model-View-ViewModel pattern, which is very relevant to this discussion.