MSDN

Cross-Platform Development with .NET MAUI

Welcome to the comprehensive guide on building truly cross-platform applications with .NET MAUI (Multi-platform App UI). .NET MAUI is the evolution of Xamarin.Forms, empowering you to create native applications for iOS, Android, macOS, and Windows from a single, shared codebase.

Leveraging a Single Codebase

The core strength of .NET MAUI lies in its ability to share code across multiple platforms. This significantly reduces development time and effort while ensuring a consistent user experience. You can write your UI, business logic, and application services once and deploy them to iOS, Android, macOS, and Windows.

Targeting Multiple Platforms

.NET MAUI provides a unified development experience for the following platforms:

Key Concepts for Cross-Platform Development

Platform Abstractions

.NET MAUI provides abstractions for common UI controls and platform features. These abstractions allow you to write platform-agnostic code that .NET MAUI then maps to the native controls and APIs of each target platform.

// Example: A cross-platform button
Button button = new Button
{
    Text = "Click Me",
    BackgroundColor = Colors.Blue,
    TextColor = Colors.White
};

// This button will render as a native UIButton on iOS, an Android Button, etc.

Platform-Specific Implementations

In scenarios where you need to leverage platform-specific features or customize the appearance beyond the standard abstractions, .NET MAUI allows you to provide platform-specific implementations. This is often done using the `OnPlatform` markup extension in XAML or conditional logic in C#.

<Button Text="Platform Specific">
    <Button.Background>
        <OnPlatform x:TypeArguments="Brush"
                    iOS="{StaticResource iOSAccentBrush}"
                    Android="{StaticResource AndroidAccentBrush}"
                    WinUI="{StaticResource WindowsAccentBrush}" />
    </Button.Background>
</Button>

Device Capabilities

.NET MAUI includes APIs to access device capabilities like sensors, location services, battery status, and more. These APIs are also designed to be cross-platform, abstracting away the underlying platform-specific implementation details.

For detailed information on accessing specific device capabilities, please refer to the Device Features documentation.

Best Practices for Cross-Platform Apps

Ready to build your next cross-platform app? Explore the Getting Started guide to begin.