I’m using MVVM Light V4 with Ninject. My ViewModel files are in separate assembly. It works great when ViewModelLocator is in start assembly (View files). Blendability works.
I want to place ViewModelLocator in ViewModel assembly, but when i do it, I’m loosing blendability. After that it’s working properly only in started application (not in design time mode).
ViewModelLocator:
static ViewModelLocator()
{
ServiceLocator.Initialize();
if (ViewModelBase.IsInDesignModeStatic)
{
using (var module = new DesignBindingsModule())
{
ServiceLocator.Load(module);
}
}
else
{
using (var module = new DefaultBindingsModule())
{
ServiceLocator.Load(module);
}
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public IMainWindowViewModel MainWindow
{
get
{
return ServiceLocator.Get<IMainWindowViewModel>();
}
}
Is it possible to put ViewModelLocator in separate assembly and bind to it in design time mode?
Problem solved. I had a bug in code. ServiceLocator was initialized two times, and throw an exception, which unable to proper binding. It’s strange that it only occurs in designer, and designer doesn’t show exception. I refactor the code and problem disappeared. I have all ViewModel relative classes in separate assembly.