Skip to content

ViewModelViewHost class

Attributes: [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-maccatalyst26.0, net10.0-macos26.0, net10.0-tvos26.0, net10.0-windows7.0, net10.0-windows10.0.19041, net10.0-windows10.0.19041, net9.0-windows7.0, net9.0-windows10.0.19041, net9.0-windows10.0.19041, net8.0-windows7.0, net8.0-windows10.0.19041, net8.0-windows10.0.19041, net462, net481

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.

The host asks the view locator for the view by the view model's run-time type, without building any type at run time, so it is safe to trim and to compile ahead of time. The default locator checks the view lookup the source generator writes, then the views the app added with Map. A view registered only with the service locator needs ViewModelViewHostUnsafe.

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 the locator registered in the service locator if...
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
DisposeReleases the resources used by the NSObject object.

Derived types

Inherited members