O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing View Model

MVVM, View Model (VM) acts as a glue and controller between View and Model. It also interacts with those libraries and services that help in CRUD (Create, Retrieve, Update, and Delete) operations on the Model.

In this recipe we will implement a View Model for our Model class, User. The View Model will also contain logic to pass data to and receive data from View. It will also interact with the data repository we implemented in our previous recipe.

How to do it...

  1. Launch Visual Studio 2012 and open WpfMVVM.sln.
  2. Add a new folder to the WpfMVVM project. Name it View Model.
  3. Add a new class to the View Model folder. Name it UserViewModel.
  4. Add a reference to the Model project.
  5. Add a private variable of type IDataRepository. Name it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required