Model- View- View Model.

Took me some times to understand what is this. The more i read the more i feel confused.
But i found this post1 and post2 describe MVVM very clear and easy to understand.


Model:
(Data)
I created a clean silverlight project (with RIA services), put this Employee.cs in folder “Model” under Silverlight project.
* Rename the file extension from ‘doc’ to ‘cs’.

View Model: (Medium Layer)
1. Create a new folder called “ViewModel” under Silverlight project.

2. Add a new class called “EmployeeViewModel.cs” in this new folder. The purpose is to actually carry the business logic to pull out data to  the next View layer. I created a simple DataHelper to help me generate data.
* Rename the file extension from ‘doc’ to ‘cs’.
VMSample

3. View (UI Layer)
Create a simple Silverlight page, here i add a Grid view to store the data, the value highlighted in Red will pull the data from View Model layer. I add ZERO code behind this xaml page:MVVMView

OK, now we have model, view model and view. You may wonder how to link all these together to make it works? Here is the magic we need to add in App.xaml.cs. In this 3 lines of code, i interpret View will connected with View model to pull out data.

MVVMLink

Advertisements