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¶
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¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [ViewModelViewHost](# class. |
Properties¶
| Name | Summary |
|---|---|
| ViewLocator | Gets or sets the [IViewLocator](# used to resolve views for the current [ViewModel](# Defaults to... |
| DefaultContent | Gets or sets the controller displayed when [ViewModel](# is null. |
| ViewModel | Gets or sets the view model whose view should be hosted. |
| ViewContractObservable | Gets or sets an observable producing view contracts. Contracts allow multiple views to be registered for the same view model but different display contexts. |
| ViewContract | Gets or sets the view contract used when resolving views. Assigning a contract produces a singleton observable under the covers. |
Methods¶
| Name | Summary |
|---|---|
| Dispose |
Inherited members
ReactiveUI.Reactive.ReactiveViewController.#ctorReactiveUI.Reactive.ReactiveViewController.#ctor(Foundation.NSCoder)ReactiveUI.Reactive.ReactiveViewController.#ctor(Foundation.NSObjectFlag)ReactiveUI.Reactive.ReactiveViewController.#ctor(System.IntPtr@)ReactiveUI.Reactive.ReactiveViewController.#ctor(System.String,Foundation.NSBundle)ReactiveUI.Reactive.ReactiveViewController.SuppressChangeNotificationsReactiveUI.Reactive.ReactiveViewController.ViewWillAppear(System.Boolean)ReactiveUI.Reactive.ReactiveViewController.ViewDidDisappear(System.Boolean)ReactiveUI.Reactive.ReactiveViewController.Dispose(System.Boolean)ReactiveUI.Reactive.ReactiveViewController.ChangingReactiveUI.Reactive.ReactiveViewController.ChangedReactiveUI.Reactive.ReactiveViewController.ThrownExceptionsReactiveUI.Reactive.ReactiveViewController.ActivatedReactiveUI.Reactive.ReactiveViewController.DeactivatedReactiveUI.Reactive.ReactiveViewController.PropertyChangingReactiveUI.Reactive.ReactiveViewController.PropertyChangedSystem.Object.Equals(System.Object)System.Object.Equals(System.Object,System.Object)System.Object.GetHashCodeSystem.Object.GetTypeSystem.Object.MemberwiseCloneSystem.Object.ReferenceEquals(System.Object,System.Object)System.Object.ToString