.NET MAUI (.NET Multi-platform App UI) is Microsoft's framework for building native mobile and desktop apps with C# and XAML from a single shared code base. It is open source and is the evolution of Xamarin.Forms, extended from mobile to desktop, with UI controls rebuilt from the ground up for performance and extensibility. This article explains how it is put together: layers, handlers, single project, startup, lifecycle, dependency injection and binding, and where it sits in the .NET 11 runtime.
The architectural layers
.NET MAUI unifies the Android, iOS, macOS and Windows APIs into a single API while still giving deep access to every native platform. Underneath, .NET provides the platform-specific frameworks: .NET for Android, .NET for iOS, .NET for Mac Catalyst and the Windows UI 3 (WinUI 3) library. They all share the Base Class Library (BCL), which hides platform details and depends on the .NET runtime.
The documentation describes three ways your code interacts with the stack:
- your app code mostly talks to the .NET MAUI controls and API layer;
- that layer directly consumes the native platform APIs;
- when needed, app code can also call platform APIs directly.
The target platforms are Android, iOS, macOS and Windows. On macOS, apps use Mac Catalyst, Apple's solution that brings a UIKit-based iOS app to the desktop and can be augmented with AppKit; on Windows, WinUI 3. The single-project page also lists Tizen among the platforms. Building for iOS and macOS requires a Mac.
Controls, virtual views and handlers
Every cross-platform control has an interface representation (for example IButton for Button); controls implementing these interfaces are called virtual views. Handlers map them to the native controls on each platform (native views), instantiate the native view and translate the cross-platform API into the native one. An example from the official page: on iOS a Button maps to a UIButton, on Android to a MaterialButton.
Handlers are reached through the control's interface, so the control never has to reference its handler and the handler never has to reference the control. Each handler exposes the native view through PlatformView and the cross-platform control through VirtualView.
Mappers and the handler lifecycle
The key concept is the mapper. A property mapper is a dictionary mapping the control's properties to the actions to run when they change; a command mapper does the same for commands sent to the native view (here a "command" is an instruction with optional data, not an ICommand). This keeps native views decoupled from controls, removes the need to subscribe to events, and makes customization easy because you can modify mappers without subclassing. Note that handlers are global: customizing one changes every control of that type in the app.
All handler-based controls raise two events: HandlerChanging (a handler is about to be created or removed, so this is the moment to unwire native events) and HandlerChanged (the native control exists and property values have been applied), with the overridable OnHandlerChanging and OnHandlerChanged methods.
Single project
The single project abstracts platform-specific experiences into one project, enabled by multi-targeting and SDK-style projects. It offers:
- one project for Android, iOS, macOS, Tizen and Windows, with simplified debug target selection;
- shared resources in the
Resourcesfolder, with dedicated build actions:MauiIcon,MauiFont,MauiImage,MauiSplashScreen,MauiAsset,MauiCss. Images are source files from which the resolutions each platform needs are generated at build time; - a single manifest for title, ID and version, merged with the native data at build time;
- the
Platformsfolder, with one subfolder per platform: only the code for the target platform is built. Multi-targeting combines with partial classes and methods or with conditional compilation (#if ANDROID,#elif IOS,#elif WINDOWS); - a single cross-platform entry point.
MauiProgram and the builder
When each platform starts, it calls the CreateMauiApp method of the static MauiProgram class, which returns a MauiApp. At a minimum it must provide the app to run:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>();
return builder.Build();
}
}
The MauiAppBuilder is the place for configuration: fonts via ConfigureFonts, services through the Services property, logging, and lifecycle events with ConfigureLifecycleEvents. The App class derives from Application and, in the latest version of the documentation, creates the window by overriding CreateWindow (for example new Window(new AppShell())); AppShell describes the app's visual hierarchy through Shell.
Lifecycle
A MAUI app moves through four states: not running, running, deactivated and stopped. The Window class raises cross-platform events for the transitions: Created, Activated, Deactivated, Stopped, Resumed and Destroying, mapped to native events (for example Android's OnResume or iOS's OnActivated for Activated). On Stopped the documentation suggests disconnecting from long-running processes and canceling pending requests; on Resumed, re-subscribing to events and refreshing the visible page; on Destroying, removing subscriptions to the native window. To react to native events, register delegates through ConfigureLifecycleEvents.
Dependency injection
.NET MAUI has built-in support for Microsoft.Extensions.DependencyInjection to manage the creation of views, view models and services. Registration normally happens in CreateMauiApp through builder.Services with AddSingleton, AddTransient or AddScoped; the types are handed to the container when Build() is called. The page warns that in non-Blazor MAUI apps AddScoped has no natural scope boundary and behaves like a singleton: use AddTransient for pages and view models, and AddSingleton for shared services.
Resolution is automatic in Shell apps through constructor injection (for example a page receiving its view model), including pages registered with Routing.RegisterRoute. Otherwise you use explicit resolution through Handler.MauiContext.Services.
Binding and MVVM
Model-View-ViewModel separates the XAML view, the data (model) and the view model acting as intermediary; view and view model are usually connected by data bindings, and the view's BindingContext is typically a view model instance. A BindingContext set on an element is inherited by its children. One useful detail: .NET MAUI marshals binding updates to the UI thread, so view model properties can be updated from any thread. Only BindableProperty properties are bindable.
MAUI and Blazor Hybrid
Blazor Hybrid support is built into .NET MAUI through the BlazorWebView control, which can be added to any page and pointed at the root of the Blazor app. Razor components run natively in the .NET process (no browser, no WebAssembly) and render the UI into an embedded web view, with full access to native device capabilities. This lets you reuse one set of web UI components across mobile, desktop and web. The control exposes configuration events such as BlazorWebViewInitializing and BlazorWebViewInitialized; on Windows, end users need the WebView2 runtime.
Where it fits in the .NET 11 runtime
In .NET 11, MAUI ships as a .NET workload plus NuGet packages, and CoreCLR is the default runtime on every MAUI platform for projects targeting .NET 11, with NativeAOT as an optional publishing alternative. This updates the picture in the "What is .NET MAUI" page, which still mentions Mono for Android, iOS and macOS. The single project remains the foundation, but in .NET 11 handlers become even more central: Shell on Android and NavigationPage, TabbedPage and FlyoutPage on iOS and Mac Catalyst move to the handler-based architecture.
Sources
- What is .NET MAUI?
- Handlers
- Target multiple platforms from .NET MAUI single project
- App lifecycle
- Dependency injection
- Data binding and MVVM
- ASP.NET Core Blazor Hybrid
- BlazorWebView
- What's new in .NET MAUI for .NET 11
Comments (0)
No comments yet.