ViewModelViewHost class¶
Attributes: [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-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¶
| 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 the locator registered in the service locator if... |
| 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 | Releases the resources used by the NSObject object. |
Derived types¶
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