Previous MAUI-Xaml-Anatomy MAUI-Behaviors Next

<Application> Tag in .NET MAUI

<Application> Tag in .NET MAUI

The <Application> tag in .NET MAUI is used in App.xaml to define the root application object. It provides a global scope for resources, styles, and configurations that apply across the entire application.

✅ Purpose of <Application>

  • Defines the application class (App.xaml.cs).
  • Holds global resources like colors, styles, and templates.
  • Sets up resource dictionaries for theming and styling.

Example: App.xaml

<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.App">
    <Application.Resources>
        <ResourceDictionary>
            <Color x:Key="PrimaryColor">#512BD4</Color>
            <Style TargetType="Label">
                <Setter Property="TextColor" Value="Black" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>
    

App.xaml.cs

The App.xaml.cs file sets the starting page of the application:

//C#
public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new AppShell(); // or MainPage = new MainPage();
    }
}
    

✅ Key Points

  • <Application> is the root container for resources, not for UI pages.
  • The starting point of the UI is defined in App.xaml.cs via MainPage or Shell.
  • You can merge multiple resource dictionaries for themes and styles.
Back to Index
Previous MAUI-Xaml-Anatomy MAUI-Behaviors Next
*