This project has moved and is read-only. For the latest updates, please go here.

Does the ViewModelLocator have a different load order then in-code DataContext assignment?

Nov 7, 2012 at 4:32 PM

When using the ViewModelLocator from the MVVM Light framework, is there a difference in the DataContext assignment order then if assigning from the code behind?

That is, would the DataContext be set at a different point in the application execution when assigning in the XAML:

<Window x:Class="MyMvvmLightApp.MainWindow"
        Title="MVVM Light Application"
        DataContext="{Binding Main, Source={StaticResource Locator}}">

versus the MainWindow.xaml.cs constructor:

public MainWindow()

    _mainViewModel = new MainViewModel();
    DataContext = _mainViewModel;


I ask, because I have a lookless control that I am using which breaks when using the Locator. Everything is fine when using the code behind assignment though. Weird.

I'd like to use the Locator though, so I can more easily assign the necessary ViewModels to the appropriate Views.

Nov 13, 2012 at 9:17 PM

In the first case, the ViewModel is created while InitializeComponent is called (or possibly even earlier, depending how you setup your ViewModelLocator). In the second case, obviously, the viewmodel is created only after InitializeComponent has completed.

Are your controls in a separate DLL?