What is .NET MAUI?
.NET Multi-platform App UI (.NET MAUI) is a framework for building native, cross-platform mobile and desktop apps with C# and XAML. It's the evolution of Xamarin.Forms, extended to support desktop scenarios.
Supported Platforms
- Android: API 21+ (Android 5.0 Lollipop)
- iOS: iOS 11+
- macOS: macOS 10.15+ (via Mac Catalyst)
- Windows: Windows 10/11 (via WinUI 3)
Creating Your First MAUI App
# Create a new MAUI application
dotnet new maui -n MyMauiApp
# Navigate to the project
cd MyMauiApp
# Build and run on Windows
dotnet build -t:Run -f net8.0-windows10.0.19041.0
XAML UI Definition
Define your UI with XAML:
<?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.MainPage">
<VerticalStackLayout Spacing="25" Padding="30">
<Label Text="Welcome to .NET MAUI!"
FontSize="32"
HorizontalOptions="Center" />
<Entry x:Name="NameEntry"
Placeholder="Enter your name" />
<Button Text="Say Hello"
Clicked="OnButtonClicked" />
<Label x:Name="ResultLabel"
FontSize="18" />
</VerticalStackLayout>
</ContentPage>
Code-Behind
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnButtonClicked(object sender, EventArgs e)
{
var name = NameEntry.Text;
ResultLabel.Text = string.IsNullOrEmpty(name)
? "Hello, World!"
: $"Hello, {name}!";
}
}
MVVM Pattern
Use the CommunityToolkit.Mvvm for clean architecture:
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private string name = string.Empty;
[ObservableProperty]
private string greeting = string.Empty;
[RelayCommand]
private void SayHello()
{
Greeting = string.IsNullOrEmpty(Name)
? "Hello, World!"
: $"Hello, {Name}!";
}
}
Next Steps
- Learn XAML fundamentals and layouts
- Implement navigation between pages
- Use platform-specific code when needed
- Publish to app stores