9

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;
  }
Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113

1 Answers1

0

Bit of a late reply our apologies.

The answer is this is deliberate.

We have stuff that will break the XAML designer if ReactiveUI's code is allowed to initialize in the constructor. Hence why we don't run the values.

Glenn Watson
  • 2,758
  • 1
  • 20
  • 30