In the static constructor of ViewModelLocator class the SimpleIoc.Default.Register<T>(); fails at IsInDesignModeStatic mode, if the Interface is in a different project. As a result the MainWindow.xaml designer is empty at design time.
I’ve made a simple solution to test it. Only changes that I’ve made is to move the DataItem class and the IDataService interface into the Domain project.
I’ve found a walk-around: Add a link to the IDataService.cs in the ClientWpf project.
public class ViewModelLocator {
static ViewModelLocator() {
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic) {
// It fails if the IDataService is in different assembly
// Delete the link of IDataService.cs from the ViewModel folder...
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
}
else {
SimpleIoc.Default.Register<IDataService, DataService>();
}
SimpleIoc.Default.Register<MainViewModel>();
}
...
}
1 Answer