These two 1-hour videos show step-by-step how to use the MVVM pattern to build simple quiz applications in both Silverlight and WPF:
Implementing Model-View-ViewModel in Silverlight
Implementing Model-View-ViewModel in WPF
What amazes me about these is how different they are structurally, for instance, how they use DataBinding:
In the Silverlight approach, we set the DataContext of a 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 just seems that every MVVM example I look at does DataContext binding in a slightly new variation and I'm trying to nail down some solid ground as to "how DataContext binding is done in the MVVM pattern".
What goes through your head when you decide to bind the DataContext to something: why bind the DataContext of a Window / View / ListBox / etc. to a ObservableCollection / ModelView / etc.? What are the advantages, disadvantages, strategies here?
Any input appreciated.