FrymasterBadgeApp/App.xaml.md

79 lines
3.1 KiB
Markdown

# App.xaml Documentation
## Overview
This is the main XAML file for the **FrymasterBadgeApp** .NET MAUI application. It defines the root `Application` object and sets up global resources that are available throughout the entire app.
## File Information
- **File**: `App.xaml`
- **Class**: `FrymasterBadgeApp.App` (partial class, paired with `App.xaml.cs`)
- **Purpose**: Application-level configuration and resource management
## XAML Content
\`\`\`xaml
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="FrymasterBadgeApp.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:FrymasterBadgeApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
\`\`\`
## Key Elements
### Root Element
- **`<Application>`** — Defines the application root.
- **`x:Class="FrymasterBadgeApp.App"`** — Links this XAML file to the partial C# class `App` in `App.xaml.cs`.
### XML Namespaces
| Namespace | Prefix | Description |
|-----------|--------|-----------|
| `http://schemas.microsoft.com/dotnet/2021/maui` | (default) | Standard .NET MAUI namespace |
| `http://schemas.microsoft.com/winfx/2009/xaml` | `x` | XAML language namespace |
| `clr-namespace:FrymasterBadgeApp` | `local` | Local application namespace (currently unused in this file) |
### Resources
The file defines **application-wide resources** inside `<Application.Resources>`:
- A `ResourceDictionary` that merges two external style files:
- **`Resources/Styles/Colors.xaml`** — Contains color definitions and brushes used across the app.
- **`Resources/Styles/Styles.xaml`** — Contains control styles, implicit styles, and other visual resources.
## Purpose & Role
- Serves as the central location for app-level resources.
- Ensures consistent theming and styling across all pages and controls.
- Loads color and style definitions early in the application lifecycle.
- Works together with `App.xaml.cs` (the code-behind) which handles logic such as theme application and window creation.
## Related Files
- **`App.xaml.cs`** — Code-behind containing constructor, theme logic, and `CreateWindow` override.
- **`Resources/Styles/Colors.xaml`** — Color palette and resource definitions.
- **`Resources/Styles/Styles.xaml`** — Global styles and control templates.
- **`MauiProgram.cs`** — Service registration and app startup configuration.
## Best Practices Demonstrated
- Clean separation of concerns: XAML for resources, C# for logic.
- Use of `MergedDictionaries` for modular and maintainable styling.
- Proper namespace declarations for future extensibility.
- Standard .NET MAUI application structure.
This file is loaded automatically when the application starts, before any pages are displayed.