Preface This post assumes you are familiar a bit with the MVVM concepts. Otherwise, here is a 5 minute overview from John PapaHow do you wire up your ViewModels to your Views in your WPF and Silverlight apps? Of course, the simplest approach is assigning your View Model’s instance to the View’s data context, in the code behind :). /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
Understanding The ViewModelLocator ConceptAn alternate way to do the above task is via a ViewModelLocator implementation, mainly so that you can preserve the Blendability - to enable designers to see see the correct preview of the View. Laurent Bugnion has a pretty neat implementation of ViewModelLocator in his MVVM Light toolkit . A simple approach to use ViewModelLoator in MVVM…