Let's talk about .NET MAUI (Multi-platform App UI)

Let's talk about .NET MAUI (Multi-platform App UI)

Hi everybody, in today's article we will talk about .NET MAUI. “New” and shiny platform from #dotnet for building cross-platform applications.

Before we start just to provide you some context, I am Almir Vuk, Microsoft MVP and Software Engineer who is working primarily on the .NET platform and using professionally Xamarin.Forms since approx 2.0 version, in the production, mobile apps. So I have professional experience with cross-platform tools and development with them.

The first thing to mention is that it all starts with .NET platform. Today .NET is a unified development platform and it can be used to build apps for a variety of platforms.

You can design cloud apps, web apps, desktop, mobile apps, games, IoT, artificial intelligence solutions, and much more.

.NET truly shines when it comes to cross-platform and multi-platform development.

The most recent version of.NET is 6.0 as of the time of this writing… and additionally, a new edition is released each year.

When it comes to the development of client apps, for example, if we are targeting mobile and desktop. There are many different platforms available out there.
You probably already know that there is a wide ecosystem of libraries, frameworks, and different programming languages that you can use to create for any of these platforms and operating systems, whether it be just one, several, or all of them.

They include several cross-platform options. Some of them let you create a separate UI while allowing cross-platform code sharing. You may create cross-platform apps using some of them, which have fully functional cross-platform API and UI framework for building the apps.

If you are part of a company or team which already has the knowledge of .NET and C# and there is a requirement to build a desktop or mobile app… Well that is where the #dotnet comes in. This year Microsoft went GA with the new cross-platform flagship framework called .NET MAUI or in a longer form “.NET Multi-platform App UI

As I already mentioned at the beginning of this article I have huge experience with Xamarin, and I am really happy and excited to write about .NET MAUI, speak at conferences, to present it for the community, and at the end of the day use it in all of my future mobile or desktop-related products.

.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps with C# and XAML. Using .NET MAUI, you can develop apps that can run on Android, iOS, macOS, and Windows from a single shared code-base.

(Source: https://docs.microsoft.com/en-us/dotnet/maui/what-is-maui)

With UI controls redesigned from the ground up for performance and extensibility, .NET MAUI is an open-source evolution of Xamarin.Forms, that has been expanded from mobile to desktop applications.

There are numerous parallels between .NET MAUI and Xamarin.Forms if you've already used those tools to create cross-platform user interfaces. There are, however, some distinctions as well. You can build multi-platform apps with NET MAUI using a single project, but you can also add platform-specific resources and source code as needed.

The ability to build as much of your app logic and UI layout in a single code base is one of the main goals of NET MAUI.

.NET MAUI is for who?

.NET MAUI is for programmers that desire to:

  • Create cross-platform apps in XAML and C# using Visual Studio IDE and a single shared codebase.
  • Cross-platform UI layout and design sharing
  • Share business logic across platforms, along with tests and code.

The main goals of .NET MAUI are:

  • Improve app performance
  • Improve simplicity of control extensibility
  • Improve the simplicity of contributing
  • Enable developer options to use Model-View-Update (MVU) and combine UI code with Blazor

Performance is a primary focus of.NET MAUI. In the past while using Xamarin.Forms, developers emphasized the importance of having applications launch as rapidly as possible..NET MAUI is improving that part as well.

.NET MAUI unifies the Android, iOS, macOS, and Windows APIs into a single API that enables developers to create code once and run it anywhere while also giving them deep access to every feature of each native platform.

The user interfaces for those desktop and mobile apps can be built using the same source code. A high-level view of a.NET MAUI app's architecture can be seen in the diagram below:

(Source: https://docs.microsoft.com/en-us/dotnet/maui/what-is-maui)

.NET MAUI applications can be created on a PC or a Mac and are packaged as native apps:

When creating an Android app with.NET MAUI, C# is first translated into an intermediate language (IL), which is then JIT-compiled into a native assembly when the program is launched.

Native ARM assembly code is entirely ahead-of-time (AOT) compiled from C# for iOS apps created with.NET MAUI.

Mac Catalyst, an Apple product, is used by macOS programs produced with.NET MAUI to bring your iOS app built with UIKit to the desktop and enhance it as necessary using additional AppKit and platform APIs.

Windows apps developed with .NET MAUI take advantage of the Windows UI 3 (WinUI 3) library to produce native Windows desktop applications.

When it comes to the building blocks of your app, a range of controls are offered by.NET MAUI and can be used to pick data, show collections, start actions, indicate activity, and more.

.NET MAUI offers more than just a group of controls; it also offers:

  • Sophisticated page design layout engine.
  • Variety of page kinds for building sophisticated navigational elements like drawers, tabs, flyout menus, etc.
  • There is a support for MVVM and data-binding
  • The simple way to extend controls is via the ability to modify handlers to improve how UI elements are shown.
  • the group of APIs that work across platforms to access native device functionalities. Thanks to these APIs, apps built with .NET MAUI may access device data like the GPS, accelerometer, battery, and network states. Cross-platform APIs for device functionality have further details.
  • A single shared project that can target Android, iOS, macOS, and Windows. A simplified debug target selection for running your .NET MAUI apps. Shared resource files within the single project. A single app manifest that specifies the app title, id, and version. Access to platform-specific APIs and tools when required. A single cross-platform app entry point.
  • With .NET hot reload, you can make changes to your managed source code and XAML while the program is still running and see the results on your device or simulator without having to rebuild it. Which increases your productivity even more.

.NET Multi-platform App UI (.NET MAUI) is the evolution of Xamarin.Forms, and by the time it will be even better and more improved. At the moment of writing this article, there is a number of issues to be resolved, but you can take a look at GitHub page and explore the different issues which developers are experiencing while using it.

This is not the end of the road, the product will grow and be improved over time, and you can help too, By providing feedback, making new issues, testing all the new features, and even contributing and fixing the small bits if you have an idea how to fix those. The team and community will be grateful for all the help.

If you have outgoing project which you plan to release next year, maybe it is a good time to start playing with the .NET MAUI. Since the knowledge you will get will be applicable in the future development of the client applications with the .NET.

Regarding the future I strongly believe that .NET MAUI will be a great platform and a very strong player, even more, stronger and more stable than Xamarin.Forms was in the whole “battle” of cross-platform frameworks. I can only say that Interesting and exciting times are coming for .NET developers in the future, and I am happy to be part of this whole wonderful ecosystem.

P.S. This text is written for European Cloud Summit Magazine, where I was a speaker in September of 2022. But I deciced to share it also with you here on my blog.

Wish you lots of luck with coding! 👌