Announcing .NET MAUI Preview 13

David Ortinau

The 13th preview of .NET Multi-platform App UI is now available in Visual Studio 17.2 Preview 1. In addition to quality improvements, this release includes several implementations such as Label.FormattedText as we close in on feature complete for the upcoming release.

hero image showcasing these controls

This entire page is a single Label control, mimicking the Windows font preview!

<Label LineBreakMode="NoWrap" LineHeight="1.4">
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Font name: Default &#010;"/>
            <Span Text="Version: 1.00  &#010;"/>
            <Span Text="Digitally Signed, TrueType Outlines &#010;"/>
            <Span Text="abcdefghijklmnopqrstuvwxyz "/>
            <Span Text="abcdefghijklmnopqrstuvwxyz &#010;" TextTransform="Uppercase"/>
            <Span Text="1234567890.:,;'+-*/=  &#010;"/>
            <Span Text="12 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="12"/>
            <Span Text="18 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="18"/>
            <Span Text="24 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="24"/>
            <Span Text="36 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="36"/>
            <Span Text="48 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="48"/>
            <Span Text="60 The quick brown fox jumps over the lazy dog. 1234567890 &#010;" FontSize="60"/>
            <Span Text="72 The quick brown fox jumps over the lazy dog. 1234567890 " FontSize="72"/>
        </FormattedString>
    </Label.FormattedText>
</Label>

Additional highlights include:

Find more details in our release notes, and in the migration guide.

One of the key .NET alignment inspired design decisions we’ve made in .NET MAUI is to adopt the Microsoft.Extensions builder pattern for bootstrapping applications.

Bootstrapping in .NET MAUI: Focus on MauiProgram

Through the course of our previews, we have heard loud and clear that you love the startup pattern in .NET MAUI. We’ve also made adjustments along the way to improve the developer experience, polish our usage, and collaborate with other .NET app model teams to arrive at a great solution for .NET MAUI developers. In this release, we’ve made another adjustment removing Microsoft.Extensions.Hosting in favor of a faster app startup time, specifically for Android. Let’s take a closer look at how a .NET MAUI app starts up each platform, and what all you can do to configure your app.

Platform App Classes

Every platform has its own native application class where you might do platform-specific setup. On Windows this is the WinUIApplication. Each of these applications will use “MauiProgram.cs” to create your MauiApp.

public partial class App : MauiWinUIApplication
{
    public App()
    {
        InitializeComponent();
    }

    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

platforms folder with app classes

Android has MainApplication, and iOS and macOS use AppDelegate. While you can put code here to do specific things, we recommend instead doing everything in MauiProgram. A barebones implementation looks like this:

namespace WeatherTwentyOne;

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

        return builder.Build();
    }
}

So what kind of work can you do here in the CreateMauiApp method? This is where you will:

  • RegisterBlazorMauiWebView – to enable this control and related services in your app
  • ConfigureEffects – to register Xamarin.Forms Effects in this .NET MAUI handler architecture
  • ConfigureEssentials – to perform Essentials related setup
  • ConfigureFonts – to register fonts with an alias
  • ConfigureImageSources – to override image sources in order to perform custom work such as filetype conversion
  • ConfigureMauiHandlers – set a custom handler as your implementation, or a 3rd-party option

Let’s say you want to replace the platform-specific implementation of an Entry control with the Fluent Design Entry control from the Maui.Graphics.Controls project. After including the NuGet package in your project, you can now configure controls to use an alternate handler implementation.

var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureMauiHandlers(handlers => {
            handlers.AddHandler(typeof(Entry), typeof(Microsoft.Maui.Graphics.Controls.EntryHandler));
        })

To make this even more convenient, library developers can provide custom builder extensions to do this for you. If I want all of my controls to render with Maui.Graphics.Controls for a Fluent implementation, I can use a convenient extension.

var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureGraphicsControls(DrawableType.Fluent)

Dependency Injection

The MauiProgram is also where you will configure your DI container. The .NET Podcast app does a clean job of demonstrating this in action with extension methods. MauiProgram.cs looks like this:

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .RegisterBlazorMauiWebView()
        .UseMauiApp<App>()
        .ConfigureEssentials()
        .ConfigureServices()
        .ConfigureViewModels()
        .ConfigureFonts(fonts =>
        {
            fonts.AddFont("Segoe-Ui-Bold.ttf", "SegoeUiBold");
            fonts.AddFont("Segoe-Ui-Regular.ttf", "SegoeUiRegular");
            fonts.AddFont("Segoe-Ui-Semibold.ttf", "SegoeUiSemibold");
            fonts.AddFont("Segoe-Ui-Semilight.ttf", "SegoeUiSemilight");
        });

    Barrel.ApplicationId = "dotnetpodcasts";

    return builder.Build();
}

Digging into ConfigureServices we see setup the BlazorWebView control, singletons, transients, scoped dependencies, and even the HttpClient implementation. View the source here.

Shell and DI – last release we featured the new constructor injection support when using Shell as your application navigation context. Until this issue is resolved, you will need to register your pages in addition to any injectables in order for the DI to succeed.

Platform Lifecycle Events

When you have need to do custom setup based on platform events, .NET MAUI provides lifecycle events right in your multi-targeted code. WinUI has a property to control if your content should extend into the title bar area or not. To access, you can do this:

builder.ConfigureLifecycleEvents(lifecycle => {
#if WINDOWS
    lifecycle
        .AddWindows(windows =>
            windows.OnNativeMessage((app, args) => {
                app.ExtendsContentIntoTitleBar = false;
            }));
#endif
});

Removing Hosting and Disabling Logging

It was identified that Microsoft.Extensions.Hosting was not needed in a .NET MAUI app, and removing it would improve Android app started by approximately 13% on a blank application. As you can see from the examples above, you can still do the most useful things with Hosting removed. Hosting was overhead we didn’t need. For more details on this change, Eric Erhardt has provided a thorough write-up here.

Hand in hand with this change, we have also made the change to disable logging for release builds.

Get Started Today

.NET MAUI Preview 13 is bundled with Visual Studio 17.2 Preview 1 available today with the latest productivity improvements for .NET MAUI development. If you are using Visual Studio 2022 17.1 Preview 2 or newer, you can upgrade to 17.2 Preview 1.

If you are upgrading from an earlier version, have been using maui-check, or run into installation problems, we recommend starting from a clean slate by uninstalling all .NET 6 previews and Visual Studio 2022 previews. Please report any issues through Help > Send Feedback

Starting from scratch? Install this Visual Studio 2022 Preview (17.2 Preview 1) and confirm .NET MAUI (preview) is checked under the “Mobile Development with .NET workload”.

Ready? Open Visual Studio 2022 and create a new project. Search for and select .NET MAUI.

Preview 13 release notes are on GitHub. For additional information about getting started with .NET MAUI, refer to our documentation.

Feedback Welcome

Please let us know about your experiences using .NET MAUI to create new applications by engaging with us on GitHub at dotnet/maui.

For a look at what is coming in future .NET 6 releases, visit our product roadmap, and for a status of feature completeness visit our status wiki.

29 comments

Comments are closed. Login to edit/delete your existing comments

  • Jorge Diego Crespo

    When will it be supported on VS for Mac? Is there any date for release candidate?
    PD: Great job!!

    • David OrtinauMicrosoft employee

      The VS Mac preview is coming along and will ship with .NET MAUI support soon. I don’t have a date.

      Release candidate will be declared once we hit feature complete and finish breaking changes. It’s a release by release call from this point on. That’s a fancy way of saying “when it’s ready”.

  • shen-juntao

    How to package MAUI-windows for other users to install and use?
    I don’t want to upload to the microsoft store, because it’s a small tool app.
    Thanks

  • Mark Dev

    Very nice.. looking at the status report and not sure if is updated looks like collectionView/Carousel are still work in progress. Basically can they be used? thanks.

    • David OrtinauMicrosoft employee

      We are reviewing CollectionView to make sure the APIs are all implemented. It’ll be updated shortly. CarouselView has one open PR for Android in addition to the CollectionView status. There are known bugs to work through.

  • panoukos41

    Will there be guides for old style projects instead of single project? It would be great to leverage shared resources and stuff but have projects seperate. Also will there be any guides for libraries with resources? thanks for the awesome work!! 😁

    • David OrtinauMicrosoft employee

      Would you want to use this for new projects, or is this a consideration for legacy projects?

      We are shipping a .NET MAUI Library project to add to your platform-specific projects. To make sure this scenario is documented I created an issue here.

      • panoukos41

        Its both. New projects feel refreshed and it would speed things up a lot, while legacy projects would only benefit by removing unnecessary stuff and ceremony 😀

  • Martin

    Is there any planning for features coming in .NET 7 (November) ? It would be nice to have some discussion about it.

  • Jura B

    Hello, I have a question. How can I use the new Sigle Project template, android and ios simulator at the same time. as with xamarin forms with visual studio 2022

  • paolo meozzi

    Is there any planning for a NET MAUI template project with the ability of create project only for specific platforms? (and not for all platoforms supported)

    Thanks

  • Shivani Ravi

    Is there any plan to provide a way to share cookies between WebView and Http client anytime soon?

    Thanks.

  • hamid Darab

    Hello.I have reported many bugs related to RightToLeft layout problems in Xamarin.Forms in Github . unfortunately none of them have been addressed in MAUI. I think if you want to make MAUI a successful multilingual & multicultural product ,you should review and change LAYOUT(positioning) process of VIEWs from the base.
    also I’d like to know is MICROSOFT going to use MAUI in his products(officially)?
    Thank You.