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

1

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;
  }
Fledgling answered 11/1, 2017 at 2:19 Comment(0)
K
1

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.

Karalynn answered 8/3, 2019 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.