Skip to main content

Posts

Showing posts with the label ViewModelBase

DependencyObject in ViewModelBase - Good or Bad?

First of all, a very-very Happy New Year to all my readers. If you are reading this post, then I’m assuming that you have a working experience of WPF using MVVM.  Don’t worry, I’m not going to re-write a huge post on what MVVM is and where to use it? This blog is very small which talks about one of the best practices any developer implementing MVVM should follow. Well, let me provide you the context first. Last week I was going through one of my colleagues’ code and noticed few interesting things in his ViewModelBase class: It was holding few Dependency properties  It was inheriting  DependencyObject  How it sounds to you? Good or … ?  Of course, that is not at all a good practice as ViewModelBase is the base class for all the ViewModels and is not supposed to contain such code. Well, this is not the only reason.  There are many other reasons which are making this implementation a BIG NO.  1 st Reason – A DependencyObject was never meant to be a Source of a bi