MVVM Light ViewModelLocator in a separate assembly? Time Mode Development Time

I am using MVVM Light V4 with Ninject. My ViewModel files are in a separate assembly. It works great when ViewModelLocator is at the beginning of the build (view files). Shift works.

I want to place the ViewModelLocator in the ViewModel assembly, but when I do this, I lose compatibility. After that, it only works correctly in a running application (not in development 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 a separate assembly and bind to it in development time mode?

+4
source share
1 answer

The problem is resolved. I had a mistake in the code. ServiceLocator has been initialized twice and throws an exception that is unable to bind correctly. It is strange that this happens only in the designer, and the designer does not show an exception. I am reorganizing the code and the problem is gone. I have all the relative ViewModel classes in a separate assembly.

0
source

Source: https://habr.com/ru/post/1395644/


All Articles