
Why Use View Model Style?
The biggest benefit is that it allows a developer to create an application with no User Interface (UI). A Designer is then able to create the entire UI using Microsoft Expression Blend 4+, without writing a single line of code.
The benefits of this include:
- The UI is easier to create when you can do it visually, in a tool, without having to write code
- You may have a better UI when it is designed and implemented by people who may not be programmers
- The UI can be created first, or at the same time, as the rest of the code, if needed
- The UI can be completely changed without the need to change any code
To achieve this, all you need to do is create a UI (a View) that has no code behind, and communicates with the application using bindings and commands that are contained in a View Model.
The Model

The Model is where the data for the application goes, The Model can contain:
- Web Services – A Silverlight application typically needs to communicate with the web server to get the data, you can put your web service methods here.
- Rest Services – The same as web services.
- Generic Collections – Basically any data.
The View Model

The View Model consists of:
- Properties – One of something. This could be a String or an Object. Implements INotifyPropertyChanged, so that any element bound to it, is automatically notified whenever it changes.
- Collections – A collection of something. This is of type ObservableCollection, so that any element bound to it, is automatically notified whenever it changes.
- Commands – An event that can be raised. Also, one parameter of type Object can be passed. This implements ICommand.
The View

This is the part that you can make with no code using Expression Blend.
An Outline
- Model
- Get your data any way you can. Usually calls to web services.
- View Model
- Consists of:
- Properties – One of something. This could be a String or an Object. Implements INotifyPropertyChanged, so that any element bound to it, is automatically notified whenever it changes.
- Collections – A collection of something. This is of type ObservableCollection, so that any element bound to it, is automatically notified whenever it changes.
- Commands – An event that can be raised. Also, one parameter of type Object can be passed. This implements ICommand.
- Implemented using Behaviors. Mostly the InvokeCommandAction Behavior
- View
- Properties
- Bind to a text box, radio button, toggle button, MediaElement, trigger an animation or ViewState change
- Collections
- Bind to List box, TreeMenu
- Commands
- Implemented using InvokeCommandAction behavior
- Bind to a ICommand in the ViewModel
- Indicate the ICommand that you want to raise
- Pass a parameter
To Learn View Model, Start Here: [RIATasks: A Simple Silverlight CRUD Example]