Things you don’t have to worry about in .NET MAUI (compared to Xamarin)

If you’re a Xamarin developer, you’re probably pretty excited about .NET MAUI. If not, you should be! Why? Let me give you some examples of things that used to be (or are) a hassle in Xamarin that won’t be in .NET MAUI.

1. Resizing images

How many hours have you spent resizing your images to hdpi, xhdpi, xxhdpi, 2x, 3x etc.? One? That’s a lie. Countless is the right answer, unless you’ve used icon packages or plugins to do the job for you. With .NET MAUI that will be a thing of the past. Just include the image with a big enough resolution and you can set it to whatever width and height you want. The Resizetizer tool by Jon Dick is built directly into the framework to do all that stuff for you behind the scenes. Neat!

2. Individual code for splash images

Do you enjoy creating a SplashActivity.cs or a SplashScreen.storyboard? No? Me neither. Do you wish you could just set the splash image for both platforms with one line of code? Well, now you can! From the new templates, look how easily you can achieve this from the single-project .csproj-file:

<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />

The Color will be the fill color you want to set if you have a transparent image such as an SVG or PNG.

3. Messy csproj-files

In Xamarin, the iOS and Android project files will very often become big merge conflict-prone behemoths. Especially if you’re dealing with a lot of resources like images and fonts, and the fact that every file has to be included explicitly. With only one SDK-style project to worry about in .NET MAUI, the days of trying to resolve merge conflicts and manually including missing files in the project should be a thing of the past.

4. .NET Standard limitations

Default Xamarin.Forms projects target .NET Standard 2.0, which defaults to C# language version 7.3. This means you don’t have access to the latest features of C#, like file scoped namespaces and global usings in C# 10. Although you can technically use the latest C# version as this blog post by James Montemagno states, you don’t get access to all the newest functionality. Since .NET MAUI is built on .NET 6, you have access to all the C# 10 functions out of the box. This also includes implicit usings, which I am not certain you get access to in Xamarin. Drop me a comment if you know anything about this.

5. Platform-specific initializations

There might be some exemptions to this, but most of your initialization done in AppDelegate and MainActivity can now be done in MauiProgram.cs. This includes things like logging, crashlytics, dependendy injection and adding fonts and handlers (formerly renderers).

6. Custom views for shadow

If you want your view elements in Xamarin.Forms to have a shadow, you either have to use a Frame or a custom view like f.ex. PancakeView. You can add a shadow to almost any layout or control in .NET MAUI and you can tweak the settings to your liking. Check out this blog post by Leomaris Reyes on shadows in .NET MAUI and the official blog post from Microsoft on this.

Did I miss something?

These are just some of the examples that I can think of, and .NET MAUI isn’t even officially out yet! Which means there could be even more goodies coming in the next previews. If I missed some killer features please let me know so I can add them to the list.

4 thoughts on “Things you don’t have to worry about in .NET MAUI (compared to Xamarin)”

  1. Nice Blog Post. You can use ImplicitUsings in Xamarin.Forms by setting the LangVersion to 10.0 in the .csproj file.

  2. How does MAUI manage the size of SpashScreens? How big should the vector image be? What dimensions should it have?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.