These two one-hour videos show step-by-step how to use the MVVM template to create simple quiz applications in both Silverlight and WPF:
Implement Model-View-ViewModel in Silverlight
Implement Model-View-ViewModel in WPF
What strikes me is how different they are from structural ones , for example, how they use a DataBinding:
In the Silverlight approach, we set the DataContext of the view to an ObservableCollection in the ViewModel :
<views:QuestionView x:Name="QuestionDataView" /> QuestionViewModel qdata = new QuestionViewModel(); qdata.FetchQuestions(); QuestionDataView.DataContext = qdata.Questions;
In the WPF approach, we set the DataContext of the window to the ViewModel itself .
<view:QuizView Margin="4" /> base.DataContext = new QuizViewModel(Quiz.Create());
It seems that every MVVM example that I am looking at is binding a DataContext to a slightly new variation, and I'm trying to mute the solid ground relatively, " like a DataContext binding in an MVVM pattern .
What happens when you decide to bind a DataContext to something: why bind a DataContext Window / View / ListBox / etc. with ObservableCollection / ModelView / etc. ? What are the advantages, disadvantages, strategies here?
Any input is appreciated.
design wpf silverlight mvvm conceptual
Edward tanguay
source share