I\'m learning WPF, MVVM Light and the ViewModelLocator pattern and running into difficulties with my main window\'s data context.
public class ViewModelLocator
The last line will work nicely if you remove the comma after d:DesignInstance
:
d:DataContext="{d:DesignInstance Type=viewModels:MainViewModel,
IsDesignTimeCreatable=True}">
Using the default data context should also work in design time:
DataContext="{Binding Main, Source={StaticResource Locator}}"
If not, try to compile the proyect and check out again.
You can manage the properties values that you want to show in design time by using the IsInDesignMode
property that the MvvmLight Toolkit
provides. By default the MainViewModel
's constructor looks like this:
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
if (IsInDesignMode)
{
// Code runs in Blend --> create design time data.
}
else
{
// Code runs "for real"
}
}
Hope this helps...