I cannot get a ViewModelViewHost
to work at design time in Visual Studio. Is this by design or have I set something up wrong?
In my view's ctor I have:
Locator.CurrentMutable.InitializeSplat();
Locator.CurrentMutable.InitializeReactiveUI();
Locator.CurrentMutable.Register(() => new SessionView(), typeof(IViewFor<SessionViewModel>));
In my view's XAML I have:
<d:DesignProperties.DataContext>
<local:MainWindowViewModel>
<local:MainWindowViewModel.ChildViewModel>
<local:SessionViewModel/>
</local:MainWindowViewModel.ChildViewModel>
</local:MainWindowViewModel>
</d:DesignProperties.DataContext>
<reactiveUi:ViewModelViewHost ViewModel="{Binding ChildViewModel}"/>
SessionView
is an IViewFor<SessionViewModel>
.
There is a comment here in the ViewModelViewHost
ctor indicating that in design mode it will return before trying to create a view. But it seems strange that InUnitTestRunner
should return true if there is a seperate InDesignMode
property for that purpose.
// NB: InUnitTestRunner also returns true in Design Mode
if (ModeDetector.InUnitTestRunner()) {
ViewContractObservable = Observable.Never<string>();
return;
}