Advertisement
Advanced .NET MAUI, Platform Integration & Handlers

How do you create a custom handler for a brand-new cross-platform control?

Short answer

Define an interface (IMyControl : IView), a cross-platform control implementing it, and a partial handler with platform-specific CreatePlatformView plus a PropertyMapper mapping your properties to native calls. Register the handler in MauiProgram via ConfigureMauiHandlers.

Save .NET MAUI mock interview
Advertisement
AModel answer
Define an interface (IMyControl : IView), a cross-platform control implementing it, and a partial handler with platform-specific CreatePlatformView plus a PropertyMapper mapping your properties to native calls. Register the handler in MauiProgram via ConfigureMauiHandlers.
public partial class VideoHandler : ViewHandler<IVideo, PlatformVideoView>
{
    public static IPropertyMapper<IVideo, VideoHandler> Mapper =
        new PropertyMapper<IVideo, VideoHandler>(ViewMapper)
        { [nameof(IVideo.Source)] = MapSource };

    protected override PlatformVideoView CreatePlatformView() => new(Context);
}
Real-world example
A team wraps each platform's native video player in one cross-platform Video control with a custom handler.
Likely follow-ups
  • How do you register a custom handler? | What is CreatePlatformView?
Related topics