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

Discussion is closed. Login to edit/delete existing comments.

  • Deepak G 0

    Is this supported in VS professional edition?

  • Tobi Baur 0

    Is it possible that Microsoft.Maui.Graphics.Controls is not yet compatible with preview 13? I can’t get the example to run, but it worked in preview 12.

  • Joren Thijs 0

    Any update on Linux support so i can make a kiosk app and deploy it to a raspberry PI?

    • Jon Miller 0

      MAUI is part of IE which is an inseparable part of the Windows operating system. So, it only runs on Windows.

      • Dave Childs 0

        Uh… what? That’s completely incorrect.

    • Stevie White (Dragnilar) 0

      @Joren

      If you need a .NET UI framework that can run on Linux, you are probably better off looking at Uno or Avalonia. The former uses UWP and the latter is a spiritual successor to WPF. The main reason I recommend looking into them (if you have not) is that Microsoft has been ambiguous about Linux support.

  • Stevie White (Dragnilar) 0

    @David

    Awesome to see Dependency Injection in action in MAUI! That is so cool.

    It’s been a while since I last tested a MAUI project out, so you’re at least getting me interested in trying it again. 🤔

  • John 0

    With preview 12 and 13 and above we are no longer able to run UI tests on iOS with .NET Maui, works with preview 11. Had to manually remove the following from the Maui project as the nuget manager wouldn’t do it:

    <ItemGroup Condition="'$(TargetFramework)' == 'net6.0-ios'">
      <PackageReference Include="Xamarin.TestCloud.Agent">
        <Version>0.23.1</Version>
      </PackageReference>
    </ItemGroup>
    
  • Joshua Burrows 0

    Cool, but without Linux support Electron seems better

  • Jammy Huang 0

    When will visual studio 2022 for Mac 17.2 be available? Is there a time schedule?

  • Trevor Tirrell 0

    Just published an app built entirely with .net maui preview 13. Having issues with iOS. Any ETA for preview 14?

  • Aria Mahlooji 0

    Hi.
    I have a question!
    Does having xamarin knowledges make it easier to learn MAUI ?

  • jamal ibrahim 0

    Migration from Xamarin Forms to .NET MAUI

    In My current project, all of my projects Libraries are in PCL format(Target Framework – .NET Portable) only. I have few questions related to .NET MAUI Migration.

    Question 1: Do I need to convert those library projects into .NET Standard – Target Framework before migrating to .NET MAUI? or it is not necessary to convert those chances.

    Question 2: Xamarin Forms PCL to .NET MAUI migration, will it be supported directly?

Feedback usabilla icon