Tuesday, 10 November 2015

Intro to MVVM light

Let us discuss about MVVM light used in the windows phone applications. This MVVM light was implemented to reduce the time to add code to the project. It is a toolkit which is developed to help the beginners to how to code in MVVM pattern. The definition of MVVM light is to accelerate the creation and development of MVVM applications in WPF, Silver-light, Windows Store, Windows Phone and Xamarin. You can refer the full document in this link.

The MVVM Light Toolkit adds the helper classes to the ViewModel by default when you install the MVVM package from the Nuget manager. It has ViewModelLocator and MainViewModel classes which helps the project to code in cleaner and easier. This MVVM light is easy to extend and manage the classes. It also creates testable applications and allows you to have thinner user interface in the view. It also maintains good security standards with some namespaces added to the library. This toolkit also help to open and edit the user interface into Blend. 

Difference between MVVM and MVVM light 

MVVM is a design pattern which is used to add code as per the patterns. i.e Our MainPage.xaml, BlankPage.xaml will be placed in View folder, Main_ViewModel.cs placed in ViewModel folder and Model.cs placed in Model folder. DataContext of the View is set with ViewModel class. MVVM is not only just file organization but also ensuring the code, is written as per the pattern too (separation of logic and all the nice stuff which should be implemented as per the pattern). We doesn't need any reference to design MVVM for our project

MVVM Light is mainly used when we need to communicate between multiple ViewModels. And we also have add on helper classes when we install MVVM light from Nuget manager as we already discussed above, given with a ViewModel folder.

How to install MVVM light to the existing project.

In your solution explorer - Add Reference - Manage Nuget packages - search for MVVM light and install to your project.

When you select install button after installing MVVM to the project it popups a dialog box with Accept and Decline button. This is to add the libraries to the project. Just select accept button.

You can see the references and classes added to the solution explorer.


Just extend your project with views and models. :)

No comments:

Post a Comment