Project Structure of .NET MAUI Application

Introduction

In this article, we will understand the project structure of a .Net MAUI Application. In the previous article of this series, we already understood How to get started with .Net MAUI. I am using the same application which we created in the previous article of this series.

.Net MAUI

What is XAML?

XAML (i.e., Extensible Application Markup Language) is XML-based markup language that is used to define the user interface in .Net Applications. There are three XAML files that are included in the project template, which are App.xaml, AppShell.xaml, MainPage.xaml. These files are platform agnostic. Each XAML file is in pair with the C# file, which is a code-behind file associated with the XAML file.

XAML

If you open the XAML file, for example, MainPage.xaml (refer to the below image), you will see xmlns which stands for XML Namespace, declared with some URI pointing to Microsoft.com. These URIs actually not pointing to some content or documentation, but actually, these are version identifiers. First, xmlns defines the tags with no prefix in the XAML Document. Example, ContentPage, ScrollView, etc. Second xmlns:x namespace defines the prefix of x. This is used for several elements and attributes which are intrinsic to XAML. Example, x.Class, x.Name etc. The third is x.Class which specifies the fully qualified .NET Class name and points to the C# code-behind file.

xml code

MauiProgram.cs class provides the entry point for the application. It enables the application to start from a single location and is used to configure fonts, services, and third-party libraries. In case you are familiar with .Net Core, you can easily relate to Program.cs class of the application. The App class mentioned in the UseMauiApp method is the root object of the application.

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

		return builder.Build();
	}
}

The App class is inherited from the Application class and is used for defining the first starting page of the application. In App.xaml.cs, you will see the MainPage is holding the reference/object of AppShell class.

public partial class App : Application
{
	public App()
	{
		InitializeComponent();

		MainPage = new AppShell();
	}
}

In AppShell.xaml, you will see ShellContent with the title as Home and ContentTemplate with route passed as MainPage, which is actually a ContentPage having an Image, a few labels with a button as shown in the below image. A ContentPage is a page that displays a single view.

Hello World

Five folders i.e., Android, iOS, MacCatalyst, Tizen, and Android, in the Platforms directory are the platform-specific files. For example, the Android directory contains Android-specific resources and configurations, the iOS directory contains iOS-specific resources and configurations, etc.

Platforms directors

Resources Directory contains a variety of resources varying from Splash Screen, Images, Fonts, Styles, Raw Assets, etc. These resources can be used in all supported platforms.

Resources

Dependencies in MAUI App can be SDKs, NuGet Packages, Third-Party Libraries, Custom Components, etc. In Properties, there is a launchSettings.json file which is used to configure the settings for launching and debugging the application. In launchSettings.json, you can configure profiles, environment variables, arguments, etc.

Dependencies


Similar Articles