Thursday, February 24, 2011

Basics Of MVVM in Silverlight

While I was doing a project using Silverlight, I had a requirement to cascade some combo boxes. As some might already know binding data to combo boxes in Silverlight is a real headache. So when I googling for some answers, I saw a lot of articles about a topic called data binding using MVVM. At first I had no idea what MVVM is and then I wanted to learn what MVVM is. After some reading I was amazed by the things that can be achieved with MVVM and I thought I might share some basics of MVVM with you all.

First of all MVVM(Model-View-ViewModel) is a great design pattern for Silverlight and Windows Presentation Foundation (which is commonly known as WPF). The MVVM has become a such overrated pattern is because it's powerful features. One of the best features of MVVM is it's close work with XAML based applications such as Silverlight.

To get a best idea about MVVM, I will explain the MVVM Triad (Model,View,View Model).
  • View is the user controls designed in XAML. Since I am mainly focuing on Silverlight, in Silverlight View is described in MainPage.xaml. 
  • The Model is used to access the data from a data source. 
  • The View Model is used the put all the logic behind the controls and to fill the gap between View and the Model. It actually bind or convert the information of Model to View information.
Using these three parts, MVVM provides powerful XAML binding for it's controls. If you are doing development with Silverlight or WPF I am sure some of you have already gone through the need of this nice pattern and if you have not gone through this pattern yet, very soon you will be going through. You can find more information and tutorials in the web on MVVM.

Happy Coding.


No comments:

Post a Comment