Implementing Model-View-ViewModel in Silverlight

Join Tim Heuer and Craig Shoemaker to learn to build a simple quiz application using Model-View-ViewModel in Silverlight.

Download code sample:

Duration: 1 hour


  • Full: 1024x768, 181MB
  • Web: 640x480, 168MB
  • Mobile: 320x240, 90MB
No Data
  • Actually, there are a few changes that should be made.  You really don't want to create a new instance of the QuestionViewModel in your view.  So the original code in the button click event works if you make a different change. You really want to set the DataContext differently.

    void Page_Loaded(object sender, RoutedEventArgs e)


      QuestionViewModel qdata = new QuestionViewModel();


      QuestionDataView.DataContext = qdata;


    Notice the change to set the DataContext to the actual View.  Now change the View's XAML to set the ItemsSource property of the ListView.

    <ItemsControl ItemsSource="{Binding Questions}">

    This way, you have bound the actual ViewModel to the DataContext of your View and you can access any of the properties of your ViewModel in the View.

    Hopefully that makes sense.

No Data