Tutorial by Examples

This a Basic example for using the MVVM model in a windows desktop application, using WPF and C#. The example code implements a simple "user info" dialog. The View The XAML <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> ...
The view-model is the "VM" in MVVM. This is a class that acts as a go-between, exposes the model(s) to the user interface (view), and handling requests from the view, such as commands raised by button clicks. Here is a basic view-model: public class CustomerEditViewModel { /// <s...
The model is the first "M" in MVVM. The model is usually a class containing the data that you want to expose via some kind of user interface. Here is a very simple model class exposing a couple of properties:- public class Customer : INotifyPropertyChanged { private string _forenam...
The View is the "V" in MVVM. This is your user interface. You can use the Visual Studio drag-and-drop designer, but most developers eventually end up coding the raw XAML - an experience similar to writing HTML. Here is the XAML of a simple view to allow editing of a Customer model. Rather...
Commands are used for handling Events in WPF while respecting the MVVM-Pattern. A normal EventHandler would look like this (located in Code-Behind): public MainWindow() { _dataGrid.CollectionChanged += DataGrid_CollectionChanged; } private void DataGrid_CollectionChanged(object sender, S...

Page 1 of 1