Microsoft Docs

.NET MAUI Documentation

Introduction to .NET MAUI

Welcome to the official documentation for .NET Multi-platform App UI (.NET MAUI). This guide will introduce you to .NET MAUI, its benefits, and how it enables you to build native cross-platform applications for Android, iOS, macOS, and Windows from a single C# codebase.

What is .NET MAUI?

.NET MAUI is an open-source, cross-platform framework for creating native mobile and desktop applications with C# and XAML. It's the evolution of Xamarin.Forms, offering a more streamlined and powerful development experience for building rich, performant applications across multiple platforms.

Key Benefits of .NET MAUI:

  • Single Project: Manage all your platform-specific code and resources in a single project.
  • Native UI: Render native user interfaces on each platform, ensuring a native look, feel, and performance.
  • Cross-Platform Reach: Target Android, iOS, macOS, and Windows from one codebase.
  • Modern .NET: Built on .NET 6 and beyond, leveraging the latest performance improvements and features.
  • Extensibility: Easily extend the framework with custom renderers and handlers.
  • Rich Ecosystem: Access the vast .NET and C# ecosystem of libraries and tools.

Core Concepts

Understanding these core concepts is crucial for effective .NET MAUI development:

  • XAML: A declarative markup language used to design your user interface.
  • C#: The primary programming language for implementing application logic and data binding.
  • Controls: Pre-built UI elements like buttons, labels, text fields, and layouts.
  • Layouts: Arrange UI elements on the screen using containers like Grid, StackLayout, and FlexLayout.
  • Data Binding: Connect UI elements to data sources, enabling automatic synchronization.
  • Platform-Specific APIs: Access native device features and APIs when needed.

Example: A Simple XAML Page

Here's a basic example of a XAML page in .NET MAUI:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyMauiApp.Views.HomePage"
             Title="Home">

    <StackLayout Padding="20" Spacing="10" VerticalOptions="Center">
        <Label Text="Welcome to .NET MAUI!"
               FontSize="32"
               HorizontalOptions="Center" />
        <Button Text="Click Me"
                Clicked="OnButtonClicked"
                HorizontalOptions="Center" />
    </StackLayout>

</ContentPage>

Example: Corresponding C# Code-Behind

And its C# code-behind for event handling:

using Microsoft.Maui.Controls;
using System;

namespace MyMauiApp.Views
{
    public partial class HomePage : ContentPage
    {
        public HomePage()
        {
            InitializeComponent();
        }

        void OnButtonClicked(object sender, EventArgs e)
        {
            DisplayAlert("Button Clicked", "You clicked the button!", "OK");
        }
    }
}
Did you know? .NET MAUI allows you to share not only your UI code but also your business logic and data models across all target platforms, significantly reducing development time and effort.

Getting Started

To start building .NET MAUI applications, you'll need:

  • Visual Studio 2022 version 17.3 or later with the ".NET Multi-platform App UI development" workload installed.
  • The .NET SDK.

For detailed setup instructions, please refer to the Installation Guide.

Next Steps

Now that you have a basic understanding of .NET MAUI, we recommend exploring the following sections: