Scripts2026年5月6日·1 分钟阅读

.NET MAUI — Build Native Cross-Platform Apps with C# and XAML

The .NET Multi-platform App UI framework for building native mobile and desktop apps for Android, iOS, macOS, and Windows from a single C# and XAML codebase.

Introduction

.NET MAUI (Multi-platform App UI) is Microsoft's evolution of Xamarin.Forms. It provides a single-project structure for building native apps that run on Android, iOS, macOS, and Windows. MAUI maps its controls to native platform widgets, so each app gets the look and performance users expect on their device.

What .NET MAUI Does

  • Maps a shared C#/XAML UI to native Android, iOS, macOS, and Windows controls
  • Provides a single-project structure with platform-specific folders for overrides
  • Supports MVVM and MVU patterns via built-in data binding and community libraries
  • Includes Blazor Hybrid mode for embedding web UI inside native app shells
  • Offers hot reload for both XAML and C# during development

Architecture Overview

MAUI sits on top of platform handler layers. Each cross-platform control (Button, Entry, ListView) delegates to a platform handler that creates and manages the native widget. The hosting model uses a MauiApp builder similar to ASP.NET, where services, fonts, and handlers are registered at startup. The single-project system uses multi-targeting with conditional compilation and platform folders. Blazor Hybrid embeds a BlazorWebView that hosts Razor components inside the native window.

Self-Hosting & Configuration

  • Requires .NET 8+ SDK with the MAUI workload installed via dotnet workload install maui
  • Develop on Windows with Visual Studio or VS Code; macOS needed for iOS builds
  • Configure app metadata in MauiProgram.cs and platform-specific Info.plist or AndroidManifest.xml
  • Add NuGet packages like CommunityToolkit.Maui for extra controls and behaviors
  • Publish with dotnet publish -f net8.0-android -c Release or use IDE publish wizards

Key Features

  • Truly native controls on each platform for authentic look and feel
  • Single-project architecture replacing the multi-head Xamarin model
  • Blazor Hybrid support for mixing web and native UI in one app
  • .NET Hot Reload for rapid iteration on XAML and C# code
  • Access to full platform APIs via dependency injection and platform-specific code

Comparison with Similar Tools

  • Avalonia — custom-rendered UI for pixel-perfect consistency; MAUI uses native controls
  • Flutter — Dart-based with custom rendering engine; MAUI leverages .NET ecosystem
  • React Native — JavaScript bridge to native views; MAUI compiles to native code via .NET
  • Kotlin Multiplatform — shares business logic across platforms; UI is platform-specific
  • Xamarin.Forms — MAUI's predecessor with similar concepts but older project structure

FAQ

Q: Is Xamarin.Forms still supported? A: Xamarin reached end of support in May 2024. Microsoft recommends migrating to .NET MAUI.

Q: Can I target Linux with MAUI? A: Linux is not officially supported. Community efforts exist, and Avalonia is a better choice for Linux desktop apps.

Q: Does MAUI work with VS Code? A: Yes. The .NET MAUI extension for VS Code provides IntelliSense, debugging, and hot reload support.

Q: How does Blazor Hybrid differ from a regular Blazor app? A: Blazor Hybrid runs Razor components inside a native WebView with full access to device APIs, while Blazor WebAssembly runs entirely in the browser sandbox.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产