liveBook · Manning

CreateMauiApp

As explained in .NET MAUI in Action

CreateMauiApp is the static startup method in a .NET MAUI template that constructs and returns the MauiApp instance.

CreateMauiApp is the static startup method in MauiProgram.cs. It uses the .NET generic host-builder pattern to construct and return the MauiApp that runs the application. section 2.3

The startup flow connects the template components in order:

  • Create a builder with MauiApp.CreateBuilder(). section 2.3
  • Call UseMauiApp<App>() to associate the application class with the host builder. section 2.3
  • Build and return the MauiApp instance. section 2.3

Template implementation

public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder.UseMauiApp<App>(); return builder.Build(); } section 2.3

Listing 2.1 MauiProgram.cs
namespace AlohaWorld;
 
public static class MauiProgram
{
    public static MauiApp CreateMauiApp()         #1
 {
        var builder = MauiApp.CreateBuilder();    #2
     builder
            .UseMauiApp<App>()                    #3
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf",  "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
        return builder.Build();                   #4
    }
}

Inspect the complete MauiProgram.cs template, including font configuration between UseMauiApp and Build. section 2.3

How .NET MAUI in Action covers it

How deep it goes
Explains builder creation, application registration, and building, but stops short of detailed platform entry-point implementation.
Examples
Uses the MauiProgram.cs template and its App-to-MainPage startup chain.
What it assumes
Assumes familiarity with static C# methods and introduces the MAUI startup pattern through the template.
What you can do after
Evaluate/understand how a .NET MAUI template constructs and launches its application.
How it connects
Connects the generic host builder, MauiApp, UseMauiApp, Application, and Page.

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.