.NET Mobile Cross‑Platform

Overview

.NET Mobile provides a unified framework for building native mobile applications that run on iOS, Android, and Windows using a single C# codebase. Powered by .NET MAUI, developers can share UI, business logic, and resources across platforms while still accessing platform‑specific APIs when needed.

Prerequisites

  • Visual Studio 2022 (or later) with the ".NET Multi‑platform App UI development" workload.
  • .NET 8 SDK or newer.
  • Android SDK, Xcode (macOS) for iOS, and Windows 10 SDK for Windows.

Setup

Open a terminal and run the following commands:

dotnet new maui -n MyCrossPlatformApp
cd MyCrossPlatformApp
dotnet build

Open the solution in Visual Studio and select the target platforms (Android, iOS, Windows) from the toolbar.

Hello World Sample

Replace the contents of MainPage.xaml with the code below to display a simple greeting.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyCrossPlatformApp.MainPage">
    <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
        <Label Text="Welcome to .NET Mobile!" 
               FontSize="24"
               TextColor="{DynamicResource Primary}" />
        <Button Text="Click Me"
                Clicked="OnButtonClicked" />
    </StackLayout>
</ContentPage>

And add the event handler in MainPage.xaml.cs:

using Microsoft.Maui.Controls;

namespace MyCrossPlatformApp
{
    public partial class MainPage : ContentPage
    {
        int count = 0;
        public MainPage()
        {
            InitializeComponent();
        }

        private void OnButtonClicked(object sender, EventArgs e)
        {
            count++;
            ((Button)sender).Text = $"Clicked {count} times";
        }
    }
}

Additional Resources