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 commands and binding data to View

In MVVM, if View wants to communicate with View Model, it is through commands. Commands are essentially classes that implement the ICommand interface. However, creating a separate class for each command required by the View makes the code base unnecessarily large. In this recipe we will develop a generic command class; the instances of which can be used by different View controls, such as buttons, to invoke a specific logic within View Model.

We will also look at how to bind data present in View Model to a control in View. We will accomplish this by binding user data in UserViewModel to the DataGrid control in MainWindow.xaml, which is our View.

How to do it...

  1. Launch Visual Studio 2012. Open

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