Goodbye Xamarin.Forms, Hello .NET MAUI!

Posted by: Gerald Versluis , on 9/9/2020, in Category Xamarin
Views: 6540
Abstract: Xamarin.Forms is evolving into .NET Multi-platform App User Interface (MAUI). In this tutorial, I will introduce .NET MAUI, the reason why Xamarin Forms is evolving to MAUI, download option (github), how you can get involved and MAUIs' release date.

If you are interested in the mobile development space, you must’ve heard by now: Xamarin.Forms is evolving into .NET Multi-platform App User Interface (MAUI).

In this tutorial, I will tell you all about the ins and outs of this change and what it might mean for you.

Don’t worry, nothing is going away!

Everything will just get faster, better and simpler for you – the developer.

Xamarin.Forms – A Little History Lesson

For those who are not familiar with what Xamarin and Xamarin.Forms is all about, let me quickly refresh your memory.

Before Xamarin was Xamarin, it had a different name and was owned by several different companies, but that is not relevant to this story.

In 2011, Xamarin, in its current form, was founded by Miguel de Icaza and Nat Friedman. With Xamarin, they built a solution with which you can develop cross-platform applications on iOS, Android and Windows, based on .NET and C#. Nowadays you can even run it on macOS, Tizen, Linux and more!!

Since developing with Xamarin was all based on the same language, you could share your code across all supported platforms, and thus reuse quite a bit.

The last piece that wasn’t reusable was the user interface (UI) of each platform.

In 2014, Xamarin.Forms was released as a solution to overcome that problem. With Forms, Xamarin now introduced an abstraction layer above the different platforms’ UI concepts. By the means of C# or XAML, you were now able to declare a Button, and Xamarin.Forms would then know how to render that button on iOS, and that same button on Android as well.

With this in place, you would be able to reuse up to 99% of your code across all platforms.

In 2016 Xamarin was acquired by Microsoft. Together with this acquisition, most of the Xamarin code became open-source and free for anyone to use under the MIT license.

If you want to learn more about the technical side of Xamarin, please have a look at the documentation here: https://docs.microsoft.com/xamarin/get-started/what-is-xamarin

 

Xamarin.Forms Today

As already mentioned, Xamarin and Forms are free and open source today!

This means a lot of people are happily using it to build their apps – both for personal development of apps as well as to create Line of business (LOB) enterprise apps. Over the years, new tooling was introduced: Visual Studio for Mac allows you to develop cross-platform solutions on Mac hardware for Xamarin apps, and also for ASP.NET Core or Azure Functions solutions.

And of course, all the Xamarin SDKs got updated with all the latest features all the way up to iOS 14 and Android 11 which have just been announced at the time of writing.

Xamarin.Forms is no different: it has seen a lot of development over the years. New features are introduced with every new version.

Not just new features; even new controls are now “in the box”. While earlier, Forms would only render the abstraction to the native counterpart; they have now introduced some controls that are composed from other UI elements.

Effectively that means Forms now has several custom controls. Currently those are: CheckBox, RadioButton and Expander for instance.

Xamarin.Forms Internals: Renderers

If we go a little deeper into how Xamarin.Forms works, we quickly find something called renderers.

Each VisualElement, which is basically each element that has a visual representation (so pages and controls mostly), has a renderer. For instance, if we look at the Button again, Button is the abstract Xamarin.Forms component which will be translated into a UIButton for iOS and an Android.Button on Android.

To do this translation, Forms uses a renderer. In this case, the ButtonRenderer. Inside of that renderer, two things happen basically:

1. Whenever a new Button (or other control) is created, all the properties are mapped to their native controls’ counterparts. i.e.: the text on a Button is mapped to the right property on the targeted platform so it shows up the right way

2. Whenever a property changes on the Button (or other control) the native control is updated as well.

The renderer controls the lifecycle of that control. You might decide that you need things to look or act a bit different, or that maybe a platform-specific feature is not implemented in Forms. For those scenarios, you can create a custom renderer. A custom renderer allows you to inherit from the default renderer and make changes to how the control is rendered on a specific platform.

If you want to learn more about renderers and custom renderers, this Docs page is a good starting point: https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/custom-renderer/

Introducing .NET MAUI and Benefits

In May 2020, the Build 2020 conference was held. Because of the current situation around the world, this was the first time this event was completely virtual, just like a lot of events. Amongst a lot of other great announcements, there was also the news that Xamarin.Forms will evolve into something called .NET MAUI. If you want to (re)watch the announcement from Build, you can see the session here on Channel 9: https://channel9.msdn.com/Events/Build/2020/BOD107.

Editorial Note: Here’s a quick recap of Build 2020 for Developers.

Notice how they are using the word evolve.

This means a couple of things.

First and most importantly: nothing will be taken away from you. Everything that is in Forms today, will be available in .NET MAUI.

Second: while everything will still be available for you, things will definitely change. The team has taken all the learnings over the past few years from Forms and will incorporate that into .NET MAUI.

There will be some breaking changes. Everything that is marked deprecated today or until .NET MAUI is released, will be removed. Also, and probably most importantly, the architecture of the renderers will change, and the namespace will change.

.net-multi-platform-app-ui-maui

Slim Renderers

In .NET MAUI, the renderers that are available right now will evolve to so-called slim renderers. The renderers will be reengineered and built from the ground up to be more performant. Again, this will be done in a way so that they should be useable in your existing projects without too much hassle.

The benefit you will get is faster apps out of the box.

You might wonder what will happen to your custom renderers? Well those should just keep working. There will probably be exceptions where it will cause some issues, but the goal here, again, is to keep everything as compatible as possible.

If you are wondering about some of the details that are shaping up as we speak, please have a look at the official Slim Renderers spec on GitHub: https://github.com/dotnet/maui/issues/28

Namespace Change

Microsoft is showing its dedication to Xamarin.Forms.

With .NET MAUI, Forms is taken into the .NET ecosystem as a first-class citizen. The new namespace will be System.Maui. By the way, Xamarin.Essentials, the other popular library, will take the same route and you can find that in the System.Devices namespace.

As you can imagine, this is quite the change and even a breaking change. The team has every intention of providing you with a transition path or tool that will make the switch from Forms to .NET MAUI, as pain free as possible.

Single Project

If you have worked with Xamarin.Forms today, you know that you will typically have at least three projects: the shared library where you want all your code to be so it can be reused, an iOS project and an Android project. For each other platform that you want to run on, you will have to add a bootstrap project in your solution.

While this is technically not a feature of .NET MAUI, .NET MAUI is the perfect candidate for this. In the future, you will be able to run all the apps from a single project.

xamarin-maui-cross-platform-simplified

Figure 2: Screenshots of how the single project structure might look like

With the single project structure, you will be able to handle resources like images and fonts from a single place instead of per platform. Platform-specific metadata like in the info.plist file will still be available. Writing platform-specific code will happen the same way as you would write multi-targeting libraries today.

See the bottom-right most screenshot in Figure 2.

Visual Studio Code Support

Another thing that has been announced is that .NET MAUI will be supported in Visual Studio Code (VS Code). This has been a long-standing wish from a lot of developers, and it will finally happen. Additionally, everything will be available in the command-line tooling as well, so you can also spin up your projects and builds from there if you wish.

Support for Multiple Design Patterns

Xamarin.Forms, and other Microsoft products for that matter, have mostly been designed to work with the Model-View-ViewModel (MVVM) pattern.

With .NET MAUI, this will change.

While MVVM will still be supported (again, nothing is taken away), because of the new renderer architecture, other patterns can be implemented now.

For instance, the popular Model View Update (MVU) pattern will now also be implemented. If you are curious what that looks like, have a look at the code below.

readonly State count = 0;
[Body]
View body() => new StackLayout
{
    new Label("Welcome to .NET MAUI!"),
    new Button(
        () => $"You clicked {count} times.",
        () => count.Value ++)
    )
};

This can even open the door to completely drawn controls with SkiaSharp for instance. This is not in any plans right now, but it’s certainly a possibility, even if it comes from the community.

.NET MAUI – Release Date, Download and Getting Involved!

After all the good news, you’re probably excited to get started, right now!

Unfortunately, it will be a while before the evolution is complete. The first preview is expected together with the .NET 6 preview which should happen in Q4 2020. The first release of .NET MAUI will happen a year after that, again with the release of the .NET 6 final; November 2021. For a more detailed roadmap, have a look at the wiki on the repository: https://github.com/dotnet/maui/wiki/Roadmap.

However, you can already be involved today. All the new plans, features, enhancements and everything will be out in the open. You can head over to the repository right now and let the team know what is important to you.

There are already lively discussions happening about all kinds of exciting new things. Also, the code is there too, so you can follow progress and even start contributing to be amongst the first contributors of this new product.

You can find the repository here: https://github.com/dotnet/maui

What Happens to Xamarin.Forms?

After the release of .NET MAUI, Forms will be supported for another year. That means; it will still get bugfixes and support until November 2022. That should give you enough time to transition to .NET MAUI with your apps.

There is also a big community supporting Xamarin and Forms, so this will also give library authors all the time they need to adapt to this new major version.

As you might have already gotten from all the new names and namespaces, the brand Xamarin is bound to disappear. Also, the iOS and Android SDKs will be renamed to .NET for iOS and .NET for Android.

I think this was always expected from the beginning when Microsoft took over. It’s just that these transitions take time.

Of course, this is very sad, the monkeys, logo and all that belongs to the Xamarin name will be history. I think it’s for the best and this means that the Xamarin framework has grown up to be a technology that is here to stay – Backed by Microsoft, incorporated into .NET, your one-stop solution for everything cross-platform.

I’m very excited to see what the future will bring, and I hope you are too!

This article was technically reviewed by Damir Arh and editorially reviewed by Suprotim Agarwal.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Gerald Versluis (@jfversluis) is a full-stack software developer and Microsoft MVP (Xamarin) from Holland. After years of experience working with Xamarin and .NET technologies, he has been involved ina number of different projects and has been building several apps. Not only does he like to code, but he is also passionate about spreading his knowledge - as well as gaining some in the bargain. Gerald involves himself in speaking, providing training sessions and writing blogs (https://blog.verslu.is) or articles in his free time. Twitter: @jfversluis Email: gerald[at]verslu[dott]is . Website: https://gerald.verslu.is


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!

Categories

JOIN OUR COMMUNITY

POPULAR ARTICLES

C# .NET BOOK

C# Book for Building Concepts and Interviews

Tags

JQUERY COOKBOOK

jQuery CookBook