Language

IViewHandler<TVirtualView,TPlatformView> Interface

Definition

Defines a strongly typed, platform-neutral view handler contract.

generic <typename TVirtualView, typename TPlatformView>
 where TVirtualView : IView where TPlatformView : classpublic interface class IViewHandler : Microsoft::Maui::IElementHandler<TVirtualView, TPlatformView>, Microsoft::Maui::IViewHandler
public interface IViewHandler<out TVirtualView,out TPlatformView> : Microsoft.Maui.IElementHandler<out TVirtualView,out TPlatformView>, Microsoft.Maui.IViewHandler where TVirtualView : IView where TPlatformView : class
type IViewHandler<'VirtualView, 'PlatformView (requires 'VirtualView :> IView and 'PlatformView : null)> = interface
    interface IElementHandler<'VirtualView, 'PlatformView (requires 'VirtualView :> IView and 'PlatformView : null)>
    interface IElementHandler
    interface IViewHandler
Public Interface IViewHandler(Of Out TVirtualView, Out TPlatformView)
Implements IElementHandler(Of Out TVirtualView, Out TPlatformView), IViewHandler

Type Parameters

TVirtualView

The cross-platform (virtual view) type this handler manages.

This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
TPlatformView

The native type this handler creates.

This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
Derived
Implements

Examples

// Works for the in-box LabelHandler and for an external backend's label handler alike. The typed
// members throw once the handler is disconnected, so guard on the nullable one first.
if (label.Handler is { PlatformView: not null } handler &&
    handler is IViewHandler<ILabel, object> labelHandler)
{
    ILabel virtualView = labelHandler.VirtualView;
    object nativeLabel = labelHandler.PlatformView;
}

Remarks

This is the IViewHandler counterpart of IElementHandler<TVirtualView,TPlatformView>. Unlike the per-control handler interfaces such as ILabelHandler, IContentViewHandler or ILayoutHandler, it does not bind PlatformView to a per-target-framework type alias, so an external platform backend can implement it with its own native types.

Both type parameters are covariant. Use object for TPlatformView to match any handler for a given virtual view type, regardless of backend.

ViewHandler<TVirtualView,TPlatformView> implements this interface, so every handler derived from it already satisfies the contract with no extra members.

Lifecycle. As with IElementHandler<TVirtualView,TPlatformView>, the typed VirtualView and PlatformView members throw InvalidOperationException rather than returning null once the handler is disconnected. Use the nullable VirtualView and PlatformView on paths that can run outside a connected window.

Properties

Name Description
ContainerView

Gets the container view for this view.

(Inherited from IViewHandler)
HasContainer

Gets or sets a value that indicates whether the PlatformView is contained within a view.

(Inherited from IViewHandler)
MauiContext

Gets the .NET MAUI context associated with the element.

(Inherited from IElementHandler)
PlatformView

Gets the native view associated with the handler.

(Inherited from IElementHandler<TVirtualView,TPlatformView>)
VirtualView

Gets the cross-platform virtual view associated with the handler.

Methods

Name Description
DisconnectHandler()

Disconnects the element handler from the element for clean up.

(Inherited from IElementHandler)
GetDesiredSize(Double, Double)

Computes the actual size of a view based on the desired size and constraints.

(Inherited from IViewHandler)
Invoke(String, Object)

Invokes the specified command on the element with the given arguments.

(Inherited from IElementHandler)
PlatformArrange(Rect)

Positions child elements and determines a size for a view.

(Inherited from IViewHandler)
SetMauiContext(IMauiContext)

Sets the .NET MAUI context for the element handler.

(Inherited from IElementHandler)
SetVirtualView(IElement)

Sets the cross-platform virtual view associated with the handler.

(Inherited from IElementHandler)
UpdateValue(String)

Updates the value of the specified property on the handler.

(Inherited from IElementHandler)

Extension Methods

Name Description
GetRequiredService<T>(IElementHandler, Type)
GetRequiredService<T>(IElementHandler)
GetService<T>(IElementHandler, Type)
GetService<T>(IElementHandler)
GetServiceProvider(IElementHandler)
IsConnected(IElementHandler)

Applies to