.NET Multi-Platform App UI (MAUI) | . NET MAUI Developer | California | Texas

Introduction

  • To create native mobile apps and desktop apps using .NET C# and XAML from a single code base.
  • Now we can create native Android, iOS, macOS, and Windows applications from a single code base.
  • This is possible using .NET’s new feature called Multi-platform App UI (MAUI). In this article, we will discuss more MAUI, Let’s get started.

What is .NET MAUI

  • As started before, MAUI means Multi-Platform App UI which is an open-source cross-platform framework. We can develop and build native Android, iOS, macOS, and Windows applications from a single code base using MAUI.
  • MAUI is an evolution of Xamarin.Forms, which extended from Mobile to Desktop applications. If you have already worked on Xamarin.Forms, you can easily relate .NET MAUI.

IDE’s for Developing MAUI Application

Xamarin Forms vs MAUI

 

  • The evolution of Xamarin forms will be integrated into the single. NET. With .NET 6, the native application development becomes a part of. NET. Single MAUI project for all platforms is the most important advantage.

The major difference between Xamarin forms and .NET MAUI

DotNet Multi Platform App UI - MAUI Developer

Common usage between Xamarin Forms and .NET MAUI

  • We still can use XAML and C# to develop the applications
  • We can choose MVVM, Reactive UI, Model-View-Update
  • We can build Android, iOS, macOS, and Windows desktop applications using the MAUI framework.

MAUI Architecture

  • In a .NET MAUI app, we write code that primarily interacts with, App code and may directly exercise platform APIs if required

MAUI Architecture

NET MAUI apps compiled into native app packages,

  • Android apps built using .NET MAUI compile from C# into an intermediate language (IL) which is then just-in-time (JIT) compiled to a native assembly when the app launches.
  • iOS apps built using .NET MAUI are fully ahead-of-time (AOT) compiled from C# into native ARM assembly code.
  • macOS apps built using .NET MAUI use Mac Catalyst, a solution from Apple that brings your iOS app built with UI Kit to the desktop, and augments it with additional App Kit and platform APIs as required.
  • Windows apps built using .NET MAUI use Windows UI Library (WinUI) 3 to create native apps that can target the Windows desktop and the Universal Windows Platform (UWP).

Features of MAUI

  • .NET MAUI provides cross-platform APIs for native device features. Here are some good features provided by MAUI,
  • Access to sensors, such as the accelerometer, compass, and gyroscope on devices.
  • Ability to check the device’s network connectivity state, and detect changes.
  • Provide information about the device the app is running on.
  • Copy and paste text to the system clipboard, between apps.
  • Pick single or multiple files from the device.
  • Store data securely as key/value pairs.
  • Utilize 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.
  • .NET MAUI includes support for .NET hot reload

MAUI for Web Applications

  • There is an option to integrate the Blazor application into MAUI using WebView.

Let’s Start with Creating MAUI Applications

  • Open a Visual Studio. Create a new .NET MAUI App

  • After clicking the create button, We have to wait for a while to load the dependencies.

MAUI Project Structure

The below image shows the project structure of the MAUI application.

  • We will see each file in this project next.

.csproj

  • First let’s look into this project file, where we can see some important details such as Target frameworks and does the project needs to use MAUI workload or not.

  • Since MAUI is a single project that is going to be deployed in multiple platforms, those platform frameworks are mentioned in the tag <TargetFrameworks>

Platforms

  • MAUI is a cross-platform framework to build Mobile and desktop applications from a single code base. Those multiple platforms are listed under the Platforms Folder.

MauiProgram.cs

  • The point of entry for our application is MauiProgram.cs.
  • It includes a configured method to pipe service registration and handler registration.

App.xaml & App.xaml.cs

  • App.xaml and App.xaml.cs file is inherited by Microsoft.Maui.Controls.Application.
  • The App.xaml will work the same as the Xamarin form and will add all the common resources and styles.

Resources

  • This folder holds the default fonts, Images, Icons, Raw, SplashScreen, and Styles. which are used in the project.

MainPage.xaml

  • This file holds the UI designs of our MAUI application.
  • This file is mostly used to define the visual contents of a page and works together with a C# code-behind file.

  • We have discussed all the folders in the MAUI Application. Let’s test the Application on all platforms.

Run the Application

  • To run the MAUI Application, we need either an Emulator or a Local Android device connected to our system for mobile application. To run our application on a local Android device, we have to enable the developer settings.

 

Output in Android Device :

.NET MAUI for Android

Output in iOS Device :

iOS app development with MAUI

Output in MacCatalyst:

Output in Windows :

Conclusion

  • In this article, we have discussed the MAUI and build a sample application.
  • I hope you all found this article useful. Happy Coding !!!
Connect With Us!