Skip to main content

Posts

Showing posts with the label MVVM

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

Safest way to use RaisePropertyChanged method - MVVM series 3 of n

Background In my previous post on  Simplest MVVM Ever , I gave the simplest overview of implementing MVVM. Now moving forward, I thought to extend my previous post by picking individual areas. And this time, I selected  RaisePropertyChanged . All the developers working on XAML related apps are very well aware about the use of this RaisePropertyChanged. I am sure, most of us are also aware on where to use this. But does everyone aware about what is the proper way or let's say generic way to use it ??? Well, even if you are not aware, no problem. At the end of this post, you will surely take home a useful tip on using  RaisePropertyChanged . Introduction As we know that MVVM provides a loose coupling methodology. At lot many places it is very useful to get benefit of such architecture, but at the cost of your alertness. Because when we are talking about MVVM, we usually says that ViewModel has no knowledge about View and properties are the way, who binds View and ViewModel to

Simplest MVVM Ever - MVVM series 2 of n

Continuation to my previous article on  WHY and WHEN of MVVM , this time, I am going to tell something on how we can create a simple MVVM application with minimal complexities. I am writing this article for those, who just want to see quickly how MVVM works. It doesn't do anything fancy and uses some basic databindings and commanding stuff. This article will be helpful for all those who are looking for a quick example of how to hook the View to the ViewModel and how commands plays a role.  Today if you will surf internet, you will came across 1000s of articles discussing on what is MVVM and what are the major building blocks of it. So, I am going to repeat the same crazy thing again. But definitely, I'll brief you about major building blocks in layman, in order to make it easier to understand for beginners. Excited, eh ???  Layman introduction of building blocks    So, let's quickly start with three main layers of MVVM. Model  - Model contains the classes which ar

Why and When of MVVM - MVVM series 1 of n

Developing software is HARD. In fact, I would say, it's very HARD. Patterns and Architectural Structures help, but... it’s still hard. Like any other architectural structures, MVVM is also a structure with a set of guidelines and NOT a set of rules. In the past few months, I came across various forums and online discussions, where people often ask "Why should I use MVVM? It seems like it complicates things" and I realized that MVVM is very difficult to learn for beginners who have very little knowledge of design patterns and frameworks. As of today, if you will search MVVM in any of the search engines, you will get lot many articles written by the extremely knowledgeable through to the novices, and it is really hard to sort the wheat from the chaff. Apart from this, there are lot of resources which mention few points and miss out others, which may be very conflicting for those beginners as well as for some experienced programmers. I'm not going to call t