Introduction
MAUI stands for Multi-platform App UI and that is now a project type among the Desktop & Mobile options in Visual Studio 2022 17.3 Preview 1, replacing the Xamarin-based option. .NET MAUI is described by Microsoft as the evolution of Xamarin.NET namespace will also be updated Xamarin. Forms will be replaced by System. Maui, and Xamarin. Essentials will be going into System.
.NET MAUI is a popular Xamarin. Forms toolkit that was released 6 years back. For years companies such as UPS, Ernst & Young, and Delta have been leveraging the Xamarin atop .NET to power their businesses; some since the very beginning. It has also been very successful in helping small businesses, maximize their development investment sharing upwards of 95% of code, and beating their competitors to market. .NET MAUI extends the success of mobile to the desktop, making it the best method to develop cross-platform apps for both, particularly for our new devices like the new Surface Duo.
.NET MAUI simplifies the choices for .NET developers, providing a single stack that supports all modern workloads that are Android, iOS, macOS, and Windows. The native features of each platform and UI are within reach in a simple, cross-platform API for you to deliver no-compromise user experiences while sharing even more code than before.
What is the use of MAUI?
NET MAUI work as. NET MAUI unifies Android, iOS, mac-os, and Windows API into a single API that allows write-once run-anywhere developer experience, while additionally providing deep access to every aspect of each platform.
How does MAUI work?
Since .NET MAUI is a simple project app, it works on a multi-target-based structure. A .NET MAUI app contains a Platforms folder, with sub folders representing platforms such as Android, iOS, and Windows to platform-specific code that starts the app on platforms.
If you only need to target Windows and mac-os with a cross-platform desktop app, then using MAUI can be a great choice because unlike many of the available cross-platform desktop frameworks, MAUI produces fully native apps, that have greater performance and OS integration compared to web UI.
.NET 6 provides a platform-specific framework for creating apps: .NET for Android, .NET for iOS, .NET for macOS, and Windows UI 3 library. All of these frameworks would be accessible to the same .NET 6 Base Class Library (BCL). which abstracts the details of the underlying platform away from your code. The BCL depends on the .NET runtime to provide the execution environment for the code.
While the BCL enables apps running on different platforms and share common business logic, the various platforms have different ways of defining the user interface for an app, and they provide various models for specifying how the elements of a user interface communicate and interoperate. we can craft the UI for every platform separately using the appropriate platform-specific framework, but this approach then requires maintaining a code-base for each device.
.NET MAUI architecture
With the .NET MAUI framework, you can build UIs for mobile and desktop applications. The below diagram shows a view of the architecture of a .NET MAUI app:
In a .NET MAUI code that primarily interacts with
- first the .NET MAUI API.
- And Then the .NET MAUI directly consumes the native platform APIs.
- Last App code may directly exercise platform APIs if required.
Features of MAUI
- MAUI provides access, such as the accelerometer, compass, and gyroscope on devices.
- Ability to check the device’s network connectivity state, and detect its changes.
- It provides information about the device the app is running on.
- Copy and paste text to the system clipboard, between the apps.
- Pick single or multiple files from the device at the same time.
- It Stores data securely as key/value pairs.
- to read text from the device Utilize built-in text-to-speech engines.
- that listen for a callback to a specific app registered URL to Initiate browser-based authentication flows.
- Most important .NET MAUI includes support for .NET hot reload.
MAUI for Web Applications
There is an choice to integrate the Blazor application into MAUI using Web-view.
create .net MAUI application
Framework –
.NET 6 Preview 6 with .NET MAUI
Platform SDK –
Android, iOS, macOS, tvOS, and Mac Catalyst
IDE –
Visual Studio 2022 preview with the workloads Desktop and Mobile
Install MAUI workloads,
dotnet workload install maui
Install Components,
dotnet tool install -g redth.net.maui.check
Check,
maui – check
If any tools and SDK required by .NET MAUI are missing, MAUI check will install them. the subsequent code shows the output generated if the tools and SDK required by .NET MAUI are already installed within the system,
On Windows, in an Administrator command prompt,
dotnet workload install maui
workloads and install them
dotnet workload install maui-android
dotnet workload install maui-ios
dotnet workload install maui-maccatalyst
dotnet workload install maui-windows
dotnet workload install microsoft-android-sdk-full
dotnet workload install microsoft-ios-sdk-full
dotnet workload install microsoft-maccatalyst-sdk-full
dotnet workload install microsoft-maccatalyst-sdk-full
dotnet workload install microsoft-macos-sdk-full
dotnet workload install microsoft-tvos-sdk-full
Building Sample Application
For creating an MAUI application First, create an application by the following command in the Command Prompt,
dotnet new maui -n HelloMaui
Next, open the Visual Studio 2022 framework and open the created project from “Open a project or solution” then find (browse) the project.
MAUI Structure
The bellow image displays the MAUI application project structure.
Run the MAUI Application
To run the MAUI Application, we require either an emulator or an area Android smartphone linked to our mobile application system. We also need to activate developer settings.
- In the Visual Studio toolbar, press the Start button to launch the app in your chosen Android emulator or Android Local Device.
- In the running app press, the CLICK ME button and observe that the count of the quantity clicks is incremented.
Conclusion
In this blog, we learned about MAUI and generated a sample application to understand how it works. We also examined its basic architecture, features, project structure, and operation. It also helps to understand how effortlessly the code interacts with MAUI features.
Author Bio:
I am working as a Digital Marketing Manager in a reputed Office 365 Add-in development company. Being a technical writing enthusiast and a goal-oriented individual with honed communication skills, I have served in the Information technology, Services, and Product industry. Having a high-energy level, I absolutely love what I do and I’m passionate about being better every day.