Chapter 8. Model View ViewModel

In this chapter, we will cover:

  • Simple MVVM applications
  • Using MVVM Light Toolkit
  • Updating the MVVM application

Introduction

Model View ViewModel (MVVM) is a UI software design pattern similar to Model View Controller (MVC). MVVM allows separation of concerns and makes the application very flexible and easy to maintain. Designers can work independently with the user interface while developers work on the model and the back-end coding.

Applications built on the MVVM pattern should have the following three distinctive layers:

  1. View: This is the front-end or user interface code such as XAML with very little or no code-behind.
  2. ViewModel: This is the code between View and Model. ViewModel acts as a bridge between the user interface and the model. This layer can have all the presentation layer code that connects to the model. This makes it easy to test the user interface functionality of the application.
  3. Model: This layer contains the classes that represent data or entities. This can include business logic and data access layers.

MVVM also will have notification mechanism to send a message to the client whenever the model data changes. This is illustrated in the following diagram:

Introduction

Multiple ideas of Views can be tested without changing the code that connects to the data. Furthermore, unit testing can be performed on the ViewModel side without any interfaces. This chapter looks into different aspects of the MVVM pattern using simple recipes to complex ones. For more information on this pattern check this article:

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset