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
