Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ViewModelViewHost work at design time for WPF? (ReactiveUI)

Tags:

wpf

reactiveui

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;
  }
like image 937
Jack Ukleja Avatar asked May 31 '26 11:05

Jack Ukleja


1 Answers

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.

like image 63
Glenn Watson Avatar answered Jun 04 '26 11:06

Glenn Watson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!