DEV Community

Cover image for .NET MAUI Closer Than Ever (Discover +5 New Features)
ByteHide
ByteHide

Posted on • Edited on • Originally published at bytehide.com

.NET MAUI Closer Than Ever (Discover +5 New Features)

Just two months ago that, after many previews, pre-releases, leaks (and a lot of waiting) Microsoft officially released the new version of its fastest full-stack web framework: .NET 6. As many of us already know, Microsoft left out many of the features that came out in the Previews since, according to them, they were not ready to be officially released.

The response from the .NET developer community has been super positive despite not releasing all the promising features and functions. There is a small chance that Microsoft expected a better response from the entire .NET developer community and apparently wants to fix this situation.

We have just started the new year and Microsoft is getting serious: Releases new Previews of the long awaited .NET MAUI.

For those who don't know, .NET MAUI is a cross-platform framework ready to create all kinds of native mobile applications with C# and XAML. It allows you to develop applications for iOS and macOS, as well as for Android and Windows.

And at this point you may be wondering….

Isn't Xamarin already there for mobile application development?

Yes, there is already Xamarin for that, but Microsoft calls .NET MAUI as the "evolution" of Xamarin.

Like Pokemon?

Yes

Source: https://www.pinterest.es/pin/770748923700305371/

To get into the topic, in the Previews released by Microsoft of .NET MAUI some very interesting features are mentioned - which hopefully, will be officially released. So let's talk about them in depth!


Windows Control Styling (Fluent Design System)

Here, David Ortinau - The Principal Program Manager at .NET MAUI - tells us that they have added design changes, now with a more fluid interface and new controls and support for themes. The main updates are:

source: https://devblogs.microsoft.com/dotnet/announcing-dotnet-maui-preview-11/


Multi-window Apps

Here is one of the most important and main features of this Preview. Now with .NET MAUI you can add multiple windows. Simply with Application.Current.Windows you can open a new window, because it contains the references of the created windows.
Let's look at the Microsoft example:

var secondWindow = new Window {
    Page = new MySecondPage {
        // ...
    }
};

Application.Current.OpenWindow(secondWindow);
Enter fullscreen mode Exit fullscreen mode

Source: https://devblogs.microsoft.com/dotnet/announcing-dotnet-maui-preview-11/


Templates and C# 10

I think the phrase with which Microsoft introduces this feature is perfect:

"Simplification is one of the main goals of .NET MAUI"

To do this, they have added the templates using C# patterns, both file-scoped namespaces and implicit usings. Besides, they have added new element templates, with which we (the developers) will save a lot of work. Let's see how it works (again I find the Microsoft example perfect):

namespace Preview11;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            });

        return builder.Build();
    }
}
Enter fullscreen mode Exit fullscreen mode

At this point you will think:

Where are the using statements?

Relax, don't worry - Microsoft says that, not me. From now on, with this new update implicit global usings will be used to gather them dynamically.


Shell and Dependency Injection

In this new feature Microsoft tells us a bit about HostBuilder. With this, .NET MAUI will have a powerful dependency injection. What Shell mainly offers is an incredible templating and styling capability to achieve in a very simple way our needs (or what we require at that moment).

To see it in a more practical way, let's look at this example:

As Microsoft tells us, we must define dependencies in the DI container.

public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>();

            builder.Services
                .AddSingleton<MainViewModel>();

            return builder.Build();
        }
    }
Enter fullscreen mode Exit fullscreen mode

And after that, we simply add in the page where we want the previously defined dependencies to be injected

public partial class MainPage
{
    readonly MainViewModel _viewModel;

    public MainPage(MainViewModel viewModel)
    {
        InitializeComponent();

        BindingContext = _viewModel = viewModel;
    }
}
Enter fullscreen mode Exit fullscreen mode

Very simple, right? Let's continue


New Navigation in .NET MAUI (Shell)

What is this from Shell? Shell (also known as AppShell) facilitates simple application designs, especially in tabs and drop-down menus.

Simply add the pages to your app and then arrange them as you like within the navigation structure. Let's see how nice it looks:

Source: https://devblogs.microsoft.com/dotnet/announcing-net-maui-preview-12/

To be honest, I think these new features are pretty cool. Clearly considering that we've just started the year (and we've been looking forward to the release of .NET 6), Microsoft plans to officially release .NET MAUI in Q2 2022.

And you, my dear reader?

  • Do you think there will be more .NET MAUI Previews?
  • What features would you like to see implemented?
  • Do you think it will finally be true and will be officially
  • released this year?

Tell me in the comments, I would like to know more about it. You are always reading about me and what I write, now I want you to share with me what you think and I will gladly read and respond in the comments🤗

Top comments (0)