liveBook · Manning

Handler

As explained in .NET MAUI in Action

A handler is a .NET MAUI component that connects a cross-platform control representation to its platform-specific native control and applies property mappings.

A handler connects a .NET MAUI control abstraction to its platform-specific native control. It acts as the glue between virtual views and native views, applying cross-platform properties through platform-specific mappings. section 11.3.1

Each control and platform has its own handler. A handler exposes PlatformView for the native control and stores property mappings that translate values such as BackgroundColor into platform-specific types. section 11.3.1 section 11.3.1

Customize an existing handler through its mapper:

  • Use PrependToMapping to add a mapping before the default mappings without overriding them. section 11.3.2
  • Use ModifyMapping to change an existing mapping, supplying that mapping’s default key. section 11.3.2
  • Use AppendToMapping to apply a customization after the defaults; this is the recommended choice in most cases. section 11.3.2
  • Place mappings in MauiProgram startup logic or in the relevant platform folders. section 11.3.2

Removing an Entry border

Suppose a custom stepper uses an Entry that looks too prominent, but .NET MAUI exposes no property for controlling its border. Append a mapping to EntryHandler.Mapper, give it a key such as RemoveBorder, and use the supplied handler instance to customize its PlatformView. The mapping action also receives the corresponding cross-platform view. section 11.3 section 11.3.2

Figure 11.11 Cross-platform controls are described by interfaces, and virtual views implement them as controls in the .NET MAUI UI layer. Handlers map the abstractions to platform-specific implementations.

Use the architecture diagram to trace a control from its cross-platform interface through its virtual view and handler to the platform-specific implementation. section 11.3.1

How .NET MAUI in Action covers it

How deep it goes
Explains abstractions, PlatformView, property dictionaries, and mapper overrides, stopping short of implementing a completely new handler.
Examples
Uses a custom stepper’s Entry border and a Button BackgroundColor mapping to illustrate platform-specific customization.
What it assumes
Assumes familiarity with .NET MAUI controls and properties while building the abstraction-to-native-control model explicitly.
What you can do after
Apply handler mappings through EntryHandler.Mapper and choose an appropriate mapper override for a control customization.
How it connects
Connects cross-platform controls, virtual views, native views, PlatformView, property mappings, and bindable properties.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.