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.
Download here
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>();
}
...
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…