.NET MAUI Platform APIs

Accessing Platform-Specific Functionality

.NET MAUI provides a unified API for common cross-platform features. However, sometimes you need to interact with native platform APIs directly to leverage unique device capabilities or implement platform-specific behaviors. The Microsoft.Maui.Platform namespace and related patterns help you achieve this safely and efficiently.

IMauiContext

Provides access to the current MAUI context, including the native platform context and services.

namespace Microsoft.Maui.Platform
interface IMauiContext

IPlatformViewDispatcher

A dispatcher that allows invoking code on the main UI thread of the native platform.

namespace Microsoft.Maui.Platform
interface IPlatformViewDispatcher

GetNativeElement()

Extension method to retrieve the native UI element from a MAUI element.

static class ViewExtensions
public static object GetNativeElement(this IView view)

MapPlatformBehaviors()

Helper methods for mapping platform-specific behaviors to MAUI elements.

static class PlatformBehaviorHelper
public static void MapPlatformBehaviors(IView mauiView, object nativeView)

Platform-Specific Implementations

Under the hood, .NET MAUI maps its abstract controls to native platform controls. You can access these native controls for fine-grained control.

iOS Specifics

Accessing UIKit elements and controllers.

using UIKit;
var nativeButton = myMauiButton.GetNativeElement() as UIButton;
nativeButton.SetTitleColor(UIColor.Red, UIControlState.Normal);

Android Specifics

Accessing Android.Views and Activities.

using Android.Views;
var nativeLayout = myMauiLayout.GetNativeElement() as ViewGroup;
nativeLayout.SetGravity(GravityFlags.CenterHorizontal);

Windows Specifics

Accessing Microsoft.UI.Xaml elements.

using Microsoft.UI.Xaml.Controls;
var nativeTextBox = myMauiEntry.GetNativeElement() as TextBox;
nativeTextBox.BorderBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Colors.Blue);

macOS Specifics

Accessing AppKit elements.

using AppKit;
var nativeTextField = myMauiEditor.GetNativeElement() as NSTextField;
nativeTextField.TextColor = NSColor.SystemPurple;

Supported Platforms

📱

iOS

Leverage the latest iOS features and APIs.

🤖

Android

Seamless integration with the Android ecosystem.

🪟

Windows

Rich desktop experiences on Windows.

🍎

macOS

Native macOS applications with modern UI.

📺

Tizen

Develop for Samsung's Tizen platform.

watchOS

Build apps for Apple Watch.