Skip to content

ViewModelViewHost class

Attributes: [RequiresUnreferencedCode("This class uses reflection to determine the view model type at runtime, which may be incompatible with trimming.")] [RequiresDynamicCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] [DebuggerDisplay("{ViewModel}, {DefaultContent}")]

Defined in

Namespace: ReactiveUI.Reactive Assembly: ReactiveUI.Reactive.dll Full name: ReactiveUI.Reactive.ViewModelViewHost Modifiers: public

Summary

View source

A controller that resolves an IViewFor implementation for the supplied ViewModel and hosts it as a child view controller.

Applies to

net10.0-ios26.0, net10.0-macos26.0, net10.0-windows10.0.19041, net10.0-maccatalyst26.0, net10.0-tvos26.0, net9.0-windows10.0.19041, net8.0-windows10.0.19041, net462, net481, net471

Class hierarchy
classDiagram
class ViewModelViewHost
class ReactiveViewController
ReactiveViewController <|-- ViewModelViewHost

Inherits from: ReactiveViewController

Remarks

ViewModelViewHost is useful when a view is responsible for projecting an arbitrary view model instance determined at runtime. The host listens for ViewModel or contract changes, resolves a view via ViewLocator, and swaps the child controller hierarchy accordingly.

Provide a DefaultContent controller to display placeholder UI while no view model is available, or set ViewContractObservable to drive platform-specific view selection.

Examples

<![CDATA[
 var host = new ViewModelViewHost
 {
 ViewModel = screen.Router.CurrentViewModel.FirstAsync().Wait(),
 ViewLocator = locator,
 DefaultContent = new LoadingViewController()
 };
 
 host.ViewContractObservable = this.WhenAnyValue(x => x.SelectedTheme);
 ]]>

Constructors

NameSummary
.ctorInitializes a new instance of the [ViewModelViewHost](# class.

Properties

NameSummary
ViewLocatorGets or sets the [IViewLocator](# used to resolve views for the current [ViewModel](# Defaults to...
DefaultContentGets or sets the controller displayed when [ViewModel](# is null.
ViewModelGets or sets the view model whose view should be hosted.
ViewContractObservableGets or sets an observable producing view contracts. Contracts allow multiple views to be registered for the same view model but different display contexts.
ViewContractGets or sets the view contract used when resolving views. Assigning a contract produces a singleton observable under the covers.

Methods

NameSummary
Dispose
Inherited members