Pages

Wednesday, May 25, 2011

Model- View- ViewModel (MVVM in WPF)

Model, View, ViewModel (MVVM) is a Design pattern used to create application. This is the result of evolution over the MVP (Model View presenter) by Microsoft.MVP which was majorly based in the Model-view-controller pattern (MVC). This MVVM is designed after keeping the modern UI development platforms (Windows Presentation Foundation and Silverlight) . This is highly preferred by the application developer of the WPF as this MVVM is most suited for the WPF application developers. The binding feature in the WPF is so powerful and that made so easy in the MVVM.

Model
The Model is defined as the data or business logic, Model is fully independent for the View, It is the separate entity and not directly related with the View. The Model can be created using the coding or it may be a pure XML for and other data file say as a Table.

View
A View is defined in XAML( Extensible Application Markup Language), the XAML does not contain ant logic in the code-behind. The XAML used to design the screen layout and the controls in the form. View is bind to the view-model with the help of data binding. The data binding is a very popular and strong feature of the MVVM patterns. Thus the Model data can be directly bind to the view using the Data binding and can be edited very easily if the binding is specified as the Two Way binding.

ViewModel
ViewModel simply referred as the “Model of a View”, it can have seen as an abstraction of the view, but ViewModel also include the Model by which the View can be bind. ViewModel contains the logic that converts the Model types into View types, and it also has the various Commands that are use to to perform operation in the View. The ViewModel exposes public properties, commands, and abstractions.


Model <<---------------- ViewModel ------------------>> View


Please check the sample application by Josh Smith that is a Very good example from here. Example. Thanks for reading my article.


Thanks,

Anil Kumar Pandey
MVP (Visual C# 2009-2010)



1 comment:

Kontera