IViewLocator interface¶
Defined in
Namespace: ReactiveUI
Assembly: ReactiveUI.Core.dll
Full name: ReactiveUI.IViewLocator
Modifiers: public abstract
Summary¶
Implement this to override how RoutedViewHost and ViewModelViewHost map view models to views.
Applies to
net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471
Class hierarchy
classDiagram
class IViewLocator
class IEnableLogger {
<>
}
IEnableLogger <|.. IViewLocator
Implements: IEnableLogger
Remarks¶
A locator typically consults an IoC container to find an IViewFor implementation for the supplied view model. Implementations may use contracts to differentiate between platform-specific or themed view registrations.
Examples¶
<![CDATA[
public sealed class CustomViewLocator : IViewLocator
{
private readonly Dictionary<Type, Func<IViewFor>> _mappings = new();
public void Register<TViewModel, TView>(Func<TView> factory)
where TViewModel : class
where TView : class, IViewFor<TViewModel>
{
_mappings[typeof(TViewModel)] = () => factory();
}
public IViewFor<TViewModel>? ResolveView<TViewModel>(string? contract = null)
where TViewModel : class
{
return _mappings.TryGetValue(typeof(TViewModel), out var factory)
? (IViewFor<TViewModel>)factory()
: null;
}
}
]]>
Methods¶
| Name | Summary |
|---|---|
| ResolveView | Resolves a view for a view model type known at compile time. Fully AOT-compatible. |