What is .NET MAUI?
.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps using C# and XAML, It supports Android, iOS, macOS, Windows, and Tizen.
Using .NET MAUI, develop apps that can run on Android, iOS, macOS, and Windows from a single shared code-base.
.NET MAUI is open-source and is evaluated from Xamarin.Forms, NET MAUI extended from mobile to desktop scenarios with rebuilt UI controls. If you have previously used Xamarin.Forms to build cross-platform user interfaces, you'll notice .NET MAUI is very similar to that. However, there are also some differences. Using .NET MAUI, you can create multi-platform apps using a single project, but you can add platform-specific source code and resources if required.
The main aims of .NET MAUI is to enable you to implement as much of your app logic and UI layout as possible as in a single code-base.
Advantages of .NET MAUI:
- Write cross-platform apps code in XAML and C#, from a single shared code-base app using Visual Studio.
- Share UI layout and design across all required platforms.
- Share code, tests, and business logic across all platforms.
How .NET MAUI works
.NET MAUI combines Android, iOS, macOS, and Windows APIs into a single API that allows a write-once run-anywhere developer experience, while additionally providing deep access to every aspect of each native platform.
.NET 6 provides a series of platform-specific frameworks for creating apps using .NET for Android, iOS, macOS, and Windows UI 3 (WinUI 3) library. These frameworks access .NET 6 Base Class Library (BCL). The BCL depends on the .NET runtime to provide the execution environment for developer code. For Android, iOS, and macOS, the environment is implemented by Mono runtime and On Windows, Win32 provides the execution environment.
BCL enables apps running on different platforms to share common business logic for all platform
.NET MAUI provides a single framework for building the UIs for all platform apps. The following diagram provide a high-level view of the architecture of a .NET MAUI app:
.NET MAUI apps can be written on PC or Mac system, and compile into native app packages:
- Android apps built using .NET MAUI and compile from C# into intermediate language (IL) which is then just-in-time (JIT) compiled to a native assembly when launching the app.
- iOS apps built using .NET MAUI and fully ahead-of-time (AOT) compiled from C# into native ARM assembly code.
- macOS apps built using .NET MAUI and use Mac Catalyst, a solution from Apple that brings iOS apps built with UIKit to the desktop, and augments it with additional AppKit and platform APIs as required.
- Windows apps built using .NET MAUI and use Windows UI 3 (WinUI 3) library to create native apps that target the Windows desktop.
.NET MAUI essentials
.NET MAUI provides cross-platform APIs for accessing native device features. Here some examples of functionality provided by .NET MAUI essentials:
- Access to sensors, like the accelerometer, compass, and gyroscope on devices.
- Check the device's network connectivity state and detect changes.
- Copy and paste text to the system clipboard, between different apps.
- Select single or multiple files from the device storage.
- Store data securely as key/value format.
- Utilise built-in text-to-speech engines to read text from the device.
- Initiate browser-based authentication flows that listen for a callback to a specific app registered URL like deep linking
.public class Startup : IStartup
public void Configure(IAppHostBuilder appBuilder)
Installing .NET MAUI
Now to install .NET MAUI, you make sure that you are using the version of Visual Studio 2022. When installing from the installer, you need the “Mobile development with .NET” workload which by default provides the “.NET MAUI (Preview)” dependencies.
Create your first application
Open Visual studio 2022 —> Click on Create new application —> Select .NET MAUI App(Preview) and click on “Nect”
Write Project name and Select location of project and Click on “Create”
After Creating application, the app looks like below screen
You can add basic configuration in MauiProgram.cs page