Blog Posts: Latest Trends and Insights in Technologies | Clarion Technologies

Migrating from Xamarin Forms to .NET MAUI

Written by Sunil Dhakne - Project Manager Delivery | Oct 20, 2023 12:48:00 PM

Xamarin has been at the forefront of cross platform app development for years! But, now there's a major change that has Xamarin developers worried!

Due to growing dissatisfaction with Xamarin.Forms over the past years, Microsoft took the bold decision to end Xamarin.Forms!

What does this mean for you?

If you are using Xamarin.Forms, then the end-of-life announcement will have a significant impact. There will be no support after April 2024, which means you will have to migrate to MAUI, the successor technology.

It's important to note that changes from Xamarin.Forms to MAUI are massive. MAUI has been written in .NET which means some adjustments are in line and this will even call for expert support.

Let's see what MAUI brings for cross-platform app development and whether shifting from Xamarin.Forms to MAUI is a smart move.

What is MAUI?

MAUI is an open-source .NET multi-platform UI framework. It's a cross platform framework used for developing mobile and desktop apps through C# and XAML. Microsoft calls MAUI an evolution of Xamarin.Forms. Microsoft called NET MAUI the future of Xamarin.Forms in their blog post. Now, although this might be a challenging move, it's essential.

So, let's check out some of the MAUI benefits.

What Are MAUI Benefits?

MAUI offers umpteen benefits that were lacking in Xamarin.Forms. Here, we have listed a few of them.

  • Microsoft built MAUI from scratch in .NET : Meaning, MAUI is a modern framework that will quickly meet current industry needs. 
  • No need for multiple projects:  In Xamarin.Forms, for every platform you needed an app, you had to create a separate project. This is a cumbersome task. MAUI makes it easy by letting you use a single project for all target platforms.
  • All the app resources will be available in one shared folder for  a better organization.
  • MAUI still keeps many Xamarin.Forms features like XAML for UI, MVVM C#, and Visual Studio, so developers do not need to relearn the technology.

Migration Efforts: Everything You Need to Know

In your journey from Xamarin Forms to .NET MAUI, the extent of the migration effort can vary depending on the size and complexity of your project.

But you're not alone in this process—Microsoft provides valuable tools and guidance to facilitate a smoother transition.

#1. Using the Upgrade Assistant

The .NET Upgrade Assistant CLI tool is a key asset in expediting the migration. It actively aids in assessing your existing Xamarin Forms project, automating certain aspects of the migration process.

Using the CLI tool is highly recommended, unless you enjoy the complexities of manually running find and replace operations within your project files. Embracing automation aligns with the efficiency of .NET Core and .NET 7.

#2. Perform Manual Migration Steps

Manual intervention remains a part of the process.

While the CLI tool is valuable, some manual steps are necessary to ensure your project builds smoothly. After all, machines are yet to replace our judgment and expertise as developers fully.

Understanding the manual update steps can provide insights into the CLI tool's operations. It will also help you comprehend the changes from Xamarin Forms to MAUI. It's a proactive approach to grasp the intricacies of the migration.

#3. Custom Renderers and Effects

Backward compatibility is available for custom renderers and effects during the migration. Although they may require some slight modifications, they are crucial in preserving your app's functionality and appearance. The migration process allows for a phased approach where Handlers can replace these custom elements.

Although the Upgrade Assistant aids in the current releases, it's complicated. A Xamarin upgrade assistant is insufficient for existing Xamarin projects with MobileProject, MobileProject.Android, or MobileProject.iOS projects. The tool must be executed separately for each project to complete the upgrade successfully.

As you proceed with the migration, remember to save the process output, as additional steps may be required afterward. By actively utilizing the Upgrade Assistant, following manual migration steps, and addressing custom renderers and effects, you can navigate the migration process more efficiently and confidently.

MAUI App Builder: What You Need to Know?

In your transition from Xamarin Forms to .NET MAUI, the MAUI App Builder is an invaluable ally, offering a suite of capabilities that reshape your migration experience.

#1. Visual UI Design:

At the core of the App Builder lies its visual UI design feature. It empowers you to effortlessly recreate the UI elements from your existing Xamarin Forms app. This user-friendly tool streamlines the design process, making it accessible to developers of all levels.

#2. Cross-Platform Adaptability:

App Builder's standout feature is its ability to create a unified codebase that adapts seamlessly to multiple platforms, including iOS, Android, Windows, and macOS. This simplifies migration, reducing the need for extensive platform-specific adjustments.

#3. Streamlined Migration:

Moving from Xamarin Forms to .NET MAUI can be daunting. But the App Builder streamlines the process. It actively speeds up the replication of your app's UI elements, aligning with the concept of a simplified migration effort.

#4. Efficiency and Familiarity:

Your existing Xamarin Essentials and Xamarin Community Toolkit are seamlessly integrated with the App Builder. This ensures efficiency and maintains a familiar environment for Xamarin developers.

.NET Startup with App Builder

When transitioning from Xamarin Forms to .NET MAUI, the first step is to actively launch a .NET MAUI project through the MAUI App Builder. This phase is important, as developers actively shape the project's foundation.

The process begins with the deliberate selection of target platforms, including iOS, Android, Windows, and macOS. This choice aligns the new project seamlessly with the platforms already served by the existing Xamarin Forms application, ensuring continuity in the user experience.

One advantage of this approach is the streamlined initialization process. Thanks to the user-friendly visual interface offered by the App Builder, it is far from cumbersome.

Developers can efficiently set up the project, reduce complexity, and accelerate the development timeline.

Creating a unified codebase is the most significant benefit. This method enables developers to write code once and employ it on various platforms. As a result, the need for extensive platform-specific adjustments during migration diminishes significantly.

In summary, harnessing the capabilities of the App Builder when initiating your project in the transition from Xamarin Forms to .NET MAUI proves to be a proactive and efficient approach.

This approach allows you to actively choose your target platforms, simplifies the initialization process, and allows unified codebase creation. Ultimately, this leads to an enhanced user experience that is both efficient and consistent across various platforms.

Custom Renderers or Mappers and Handlers: In the context of migrating from Xamarin Forms to .NET MAUI, you'll encounter essential choices related to customizing native controls and enhancing your app's performance. Two primary options stand out: Custom Renderers and Mappers and Handlers.

Custom Renderers: Custom renderers have been a pivotal tool in Xamarin Forms for enhancing the native controls of your application. In .NET MAUI, they are still available but primarily for backward compatibility.

You can conveniently register these custom renderers in the MAUI App Builder, ensuring a smoother transition from Xamarin Forms to .NET MAUI.

There are a significant number of Xamarin Forms projects that use a custom renderer. You may want to convert them immediately, depending on how many custom renderers your project has. It is okay to keep using custom renderers if there are too many.

Mappers and Handlers: Mappers and Handlers have emerged as viable alternatives to Custom Renderers. They serve the same essential purpose – customizing native controls when the built-in options prove insufficient. A significant advantage of Mappers and Handlers is their potential to enhance app performance by streamlining the page hierarchy in the compiled application. Read more about them in the MAUI documentation.

Xamarin Essentials and Xamarin Community Toolkit

Both Xamarin Essentials and Xamarin Community Toolkit are updated to work with MAUI. 

Xamarin Essentials

Source: 
Xamarin Essentials offers cross-platform APIs that simplify everyday tasks such as device sensors, connectivity, file management, and more. The good news is that Xamarin Essentials is part of core MAUI and offers the benefit of maintaining your app's core functionality during migration.

Xamarin Community Toolkit

Source:

The Xamarin Community Toolkit enhances Xamarin apps. With this toolkit, you can create engaging and feature-rich interfaces in .NET MAUI by using a rich set of UI components.

A wide range of powerful tools are available through the Xamarin Community Toolkit, including data grids, animations, and much more.

In addition to maintaining a consistent and polished user experience, you can take advantage of the capabilities offered by the .NET MAUI framework by integrating these components into your .NET MAUI project.

Is Migration Worth It?

Yes. Migration from Xamarin.Forms to MAUI is worth it for few reasons. Firstly, in Xamarin.Forms, you were making separate projects for each target platform. This means maintaining more than one codebase. This is not an issue with MAUI, as you can manage multiple platforms through a single project. Thus reducing your maintenance efforts.

Conclusion

Change is part of the software world. Migration from Xamarin.Forms to MAUI will help you improve our app's performance. This migration will also force you to look deeper into your apps to weed out anything that's not helpful.

As always, experts play a crucial role in migration. Thousands of things can go wrong if you don't know how to handle migrations. But worry not; our Xamarin developers are here for your help. With decades of experience and a talent pool of best-in-class developers, Clarion Technologies can help you turn your vision into reality. Get in touch with us today!

FAQs

Q1. We need to learn more about MAUI. Where to go?

Microsoft did a good job on MAUI documentation. You can access it here.

Q2. Should you move all your Xamarin.Forms apps to MAUI?

The answer is it depends! If you need the new MAUI features, migration is worth it. If you are satisfied with Xamarin.Forms, you still have plenty of time to migrate.

Q3. What is .NET MAUI used for?

.NET MAUI is used to create cross-platform apps with C# and XAML.

Q4. Is .NET MAUI better than Xamarin?

Undoubtedly, .NET MAUI is a better and more modern framework to solve current challenges. Building on .NET 6 brings improved productivity, app performance, and a better, organized development experience.