Saturday, 4 February 2023

 

Xamarin Versus .NET MAUI


Trust you are presently acquainted with these two names, Xamarin.Forms and .NET MAUI, particularly assuming that you will foster cross-stage applications. While attempting to pick either, some of you may be dubious.

In this blog, I will attempt to assist you with better figuring out the distinctions among Xamarin.Forms and .NET MAUI.

Xamarin.Forms: Outline

Xamarin.Forms is by and large used to foster local cross-stage applications. Fundamentally, Xamarin.Forms is a layer of deliberation that permits collaboration of the common code with the hidden stage code of Android, iOS, and Windows.

Utilizing Xamarin.Forms, a cross-stage portable application engineer can save improvement time by composing all of their business rationale in a solitary language. Practically 90% of the code expected to create an application is shared across stages, allowing you to accomplish local execution and a similar look on each.

.NET MAUI: Outline
As you most likely are aware, the .NET Multi-stage Application UI is prominently known as .NET MAUI. It is utilized to fabricate local cross-stage applications with .NET for Android, iOS, macOS, and Windows. .NET MAUI is based on top of Xamarin.Forms, advancing the stage to a higher level.

With .NET MAUI, Microsoft starts an excursion to make a bound together .NET stage as a solitary base class for .NET Center and Mono/Xamarin together.

Shared characteristics
Since .NET MAUI is a development of Xamarin.Forms, they share the majority of their elements for all intents and purpose. You can get practically everything in .NET MAUI that Xamarin has, similar to controls, designs, Shell, signals, layouts, and cross-stage APIs for gadget highlights. You can see as every one of these in .NET MAUI with an alternate namespace.

Xamarin versus .NET MAUI
Despite the fact that there are numerous things in like manner among Xamarin.Forms and .NET MAUI, there are a ton of contrasts, as well. I will use whatever is left of this blog examining the really 15 contrasts.

1. Platform Architecture

First and foremost, the main change in platform architecture is that .NET MAUI is integrated with .NET 6.0 to be a part of the Journey to One .NET.

Xamarin

.NET MAUI

Xamarin.Forms ArchitectureXamarin.Forms Architecture

.NET MAUI Architecture.NET MAUI Architecture



Uses separate projects for each platform.

Single project structure: each platform can be targeted using devices about to be deployed.

Platform-dependent files and code are maintained under different projects.

The platform-dependent files and code are maintained under platform folders and platform filename targets such as MainPage.android.cs and MainPage.iOS.cs.

Project system: Franken-proj.

Project system: SDK Style.


With Xamarin.Forms, developers may become frustrated working with multiple projects targeting multiple platforms; keeping images, fonts, and platform-related code organized; adding different dependencies, and resolving them if they’re referenced as NuGet packages. Encountering these problems, developers are now addressed in .NET MAUI with a single project.

Since .NET MAUI is a simple project app, it works on a multitarget-based structure. A .NET MAUI app contains a Platforms folder, with subfolders representing platforms such as Android, iOS Maccatalyst, and Windows to target platform-specific code that starts the app on platforms. It can also be multitargeted based on your own file name. Generally, the file name target pattern is to include the platform as an extension in the file name. For example:

  • MainPage.android.cs targeting Android

  • MainPage.iOS.cs targeting iOS and Mac

  • MainPage.Windows.cs targeting Windows

2. Supported Platforms and Versions

The main difference in platform support between Xamarin and .NET MAUI is in their support for Windows. Xamarin supports UWP, whereas .NET MAUI supports WinUI. Have a look at the following table for support version details.

Xamarin

.NET MAUI

Primary support

  • Android 4.4 (API 19) or higher (more details).

  • iOS 9 or higher.

  • UWP: Windows 10, build 10.0.16299.0 or greater for .NET Standard 2.0 support.

Primary support

  • Android 5.0 (API 21) or higher.

  • iOS 10 or higher.

  • macOS 10.13 or higher

  • WinUI: Windows 11 and Windows 10 version 1809 or higher

Additional platform support

  • Samsung Tizen

  • macOS 10.13 or higher

  • GTK#

  • WPF

Additional platform support

  • Tizen, supported by Samsung.

  • Linux, supported by the community.


3. .NET CLI

Another major difference is that .NET MAUI runs on .NET CLI. The .NET command-line interface (CLI) is a cross-platform toolchain for developing, building, running, and publishing .NET apps. This .NET CLI provides .NET MAUI apps with a seamless build and run experience.

Xamarin

.NET MAUI

Xamarin supports .NET Framework to build and run apps.

.NET MAUI supports the .NET CLI toolchain to build, run, and publish .NET apps.

4. Renderer and Handler Architectures

In Xamarin, controls are made with renderers. When developers want to customize a native controls’ UI, they must use a custom renderer to do so. These renderers cost the users heavily in terms of performance and app size.

But .NET MAUI uses handler architecture that is very loosely coupled with native assembly. With a native platform, this results in a lightweight app with better performance.

You can use renderers here if needed. You can reuse Xamarin.Forms custom renderer when porting.

Xamarin

.NET MAUI

Uses renderer architecture.

Uses handler architecture.

Tightly coupled with native controls.

Loosely coupled with native controls.

You cannot use handlers here.

You can use renderers here if needed. You can reuse Xamarin.Forms custom renderer when porting.

Xamarin Renderer ArchitectureXamarin Renderer Architecture

.NET MAUI Handler Architecture.NET MAUI Handler Architecture

5. .NET 6

.NET MAUI is integrated into .NET 6, whereas Xamarin.Forms is a .NET Framework. Due to .NET 6 integration, you can use the following .NET 6 and C#10 features in .NET MAUI:

Note: If you are porting your app from Xamarin.Forms to .NET MAUI, you may not be able to use all these .NET 6.0 and C# features, because you may face limitations on your existing code.

6. Resource Maintenance

.NET MAUI took over Xamarin in terms of resources, especially in terms of images. You do not need to maintain a set of images for the platform- or device-specific needs. A single SVG image is enough to meet all platform and device requirements. The SVG image gets turned into a .png image to work on all platforms.

Xamarin

.NET MAUI

Resources include images and classes.

Resources include classes like MauiImage and MauiResources.

Need to maintain resolution-based images for platform-specific devices.

With the help of SVG images, there is no need to maintain platform-specific or device-specific images.

Resource files need to be maintained separately for each platform.

Resources can be maintained in a single location.


7. Hot Reload Support

Support for hot reload in Xamarin versus .NET MAUI is detailed in the table.

Xamarin

.NET MAUI

.NET hot reloads

  • Does not support (but UWP has limited support for runtime edits using .NET’s edit and continue feature).

.NET hot reloads

XAML hot reload

  • Experimental: SDK 4.x and Visual Studio 2019 prior to version 16.9.

  • Feature complete: SDK 5.x and Visual Studio 2019 version 16.9 or newer.

XAML hot reload

  • Complete support available.

8. Graphics APIs

In Xamarin, there is no direct API available to fulfill any drawing requirements. You have to do it on the native side using renderers. But .NET MAUI now abstracts native drawing and brings you better graphics APIs.  The cross-platform graphics functionality in .NET MAUI provides a drawing canvas for drawing and painting shapes.

The brush is the primary type.

 

Xamarin

.NET MAUI

No graphics available.

Graphics modes such as paint, winding,blend are available.

Custom drawing is not possible.

Drawing graphics is possible.

Color is the primary type.

Brush is the primary type.

9. Configuring Resources and Services

Unlike Xamarin, .NET MAUI apps are bootstrapped using the .NET Generic Host. So, if you want to initialize any fonts, services, or third-party libraries, it can be done through that from a single location.

10. Accessibility

Typically in Xamarin, we use automation properties and native APIs to provide proper accessibility to screen readers for text in the controls used in an app.

But .NET MAUI provides semantic properties to provide accessibility values in apps (you can use automation properties in .NET MAUI, but the recommended approach is semanticproperties).

11. Supported Patterns

Another important difference is pattern support.

Xamarin

.NET MAUI

  • MVVM (model-view-viewmodel)

  • RxUI (ReactiveUI) patterns

  • MVVM (model-view-viewmodel)

  • RxUI (ReactiveUI) patterns

  • MVU patterns (still experimental)

12. Blazor apps

Developing Blazor hybrid apps is not possible in Xamarin, but you can build .NET MAUI Blazor apps.

13. Cross-platform APIs for device features

Both Xamarin and .NET MAUI can provide the following cross-platform APIs for native device features. According to this Microsoft documentation, the following are the cross-platform APIs available.

  • 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.

Cross-platform APIs for device features are also integrated with MAUI under Microsoft.Maui.Essentials namespace.

Xamarin

.NET MAUI

Cross-platform APIs for device features can be carried out using Xamarin.Essentials.

Cross-platform APIs for device features are also integrated with MAUI under Microsoft.Maui.Essentials namespace.

14. Multiple Windows

In .NET MAUI, multiple windows can be opened on Android, iOS on iPad, Mac Catalyst, and Windows at a time. This support is not available in Xamarin.




No comments:

Post a Comment

All About .NET MAUI

  What’s .NET MAUI? .NET MAUI (.NET Multi-platform App UI) is a framework for building modern, multi-platform, natively compiled iOS, Androi...

Ads2