| MAUI-index :👈 | 👉:XAML-in-MAUI |
.NET MAUI Solution Layout |
π¦ .NET MAUI Solution Layout (Project Structure)
MAUI uses a single-project structure that multi-targets platforms while sharing most of your app code and assets. Below is a practical map of what lives where, why it matters, and how it all fits together.
π§ High-level structure
The typical MAUI solution has one .sln (solution) and one primary project (.csproj) that targets Android, iOS, Mac Catalyst, and Windows. Platform-specific files live under a unified Platforms/ folder, while shared UI and assets sit at the root.
ββ π MyMauiApp.sln
ββ π MyMauiApp/ β single project (multi-target)
ββ π MyMauiApp.csproj
ββ π MauiProgram.cs β DI + app builder
ββ π App.xaml / App.xaml.cs β app shell & resources
ββ π Views/ β pages & screens (XAML/CS)
ββ π ViewModels/ β MVVM view models
ββ π Models/ β domain/data models
ββ π Services/ β data/services/APIs
ββ π Controls/ β custom controls
ββ π Helpers/ β utilities/extensions
ββ π Resources/ β shared assets (fonts, images, styles)
ββ π Platforms/ β per-platform code & manifests
ββ π Themes/ β color styles, dictionaries
ββ π Tests/ β unit/UI tests (optional)
ββ π README.md / .editorconfig / .gitignore (optional)
ποΈ Top-level files
- π Solution (.sln): Groups projects; usually just one MAUI project unless you separate libraries.
- π Project (.csproj): Defines TargetFrameworks, assets, build settings, NuGet packages, and MSBuild items for MAUI.
- βοΈ MauiProgram.cs: Entry point for configuring the MAUI app, dependency injection, handlers, and services.
- π§© App.xaml / App.xaml.cs: Global resources, styles, Shell configuration, and application lifecycle hooks.
- πΊοΈ Shell: Optional
AppShell.xamlfor navigation structure (tabs, flyouts, routes).
// MauiProgram.cs (core setup)
using Microsoft.Maui;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
namespace MyMauiApp;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("Inter-Regular.ttf", "InterRegular");
fonts.AddFont("Inter-SemiBold.ttf", "InterSemiBold");
});
// Dependency injection
builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<MainViewModel>();
builder.Services.AddTransient<IDataService, DataService>();
return builder.Build();
}
}
π§± Common shared folders
πΌοΈ Resources
- πΌοΈ Images: Put PNG/SVG/WEBP in
Resources/Images. MAUI auto-generates platform variants (scales/densities) at build. - π€ Fonts: Place TTF/OTF in
Resources/Fontsand register inMauiProgram.cs. Use the alias in XAML/C#. - π¨ Styles: Resource dictionaries in
Resources/StylesorThemes/for colors, typography, and control styles. - π¬ App icons/splash:
Resources/AppIconandResources/Splashwith a single source image; MAUI generates platform-specific outputs. - π¦ Raw assets: Files in
Resources/Rawaccessed viaFileSystem.OpenAppPackageFileAsync.
π§© Views, view models, models
- π§© Views: XAML page files like
MainPage.xamland code-behind, plus custom controls inControls/. - π§ ViewModels: MVVM classes with INotifyPropertyChanged; register in DI for constructor injection.
- π Models: Immutable or simple POCOs representing domain/data entities.
π§ Services and helpers
- π Services: API clients, repositories, local storage; abstract behind interfaces for testing.
- π§° Helpers: Converters, behaviors, extension methods, platform checks.
- π§ Navigation: Centralize navigation via Shell routes or an abstraction over
INavigation.
π₯οΈ Platforms folder
Platform-specific code and manifests live here. Use conditional compilation and partial classes to wire platform features while keeping the shared code clean.
- π€ Android:
AndroidManifest.xml,MainActivity.cs,MainApplication.cs, platform services (e.g., notifications, permissions), and resource overrides. - π± iOS:
Info.plist,AppDelegate.cs,SceneDelegate.cs, entitlements, and iOS-specific implementations. - π₯οΈ Mac Catalyst:
Info.plist,AppDelegate.cs, Catalyst-specific configurations (menu items, window behaviors). - πͺ Windows:
Package.appxmanifest,App.xaml.cspartials, WinUI host, toast notifications, and windowing APIs.
// Example: conditional platform code
#if ANDROID
// Android-specific implementation
#elif IOS
// iOS-specific implementation
#elif WINDOWS
// Windows-specific implementation
#endif
π§ Project file essentials (.csproj)
Your project file defines targets, assets, and MAUI build behaviors. MAUIβs single project uses multi-targeting to build per-platform binaries.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ApplicationTitle>MyMauiApp</ApplicationTitle>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<MauiImage Include="Resources/Images/.png" />
<MauiSplashScreen Include="Resources/Splash/splash.svg" Color="#ffffff" />
<MauiIcon Include="Resources/AppIcon/appicon.svg" />
<MauiFont Include="Resources/Fonts/.ttf" />
<None Include="Resources/Raw/**" Pack="true" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="x.y.z" />
</ItemGroup>
</Project>
π§ Navigation and app lifecycle
- πΊοΈ Shell navigation: Define routes in
AppShell.xamland navigate viaShell.Current.GoToAsync("route"). - π Lifecycle: Handle
OnStart,OnSleep,OnResume-like behaviors viaApplicationevents and platform-specific callbacks. - π§© Dependency injection: Register views, view models, and services in
MauiProgram.csand resolve via constructor injection.
// Register routes (AppShell.xaml.cs)
Routing.RegisterRoute("details", typeof(DetailsPage));
// Navigate
await Shell.Current.GoToAsync("details");
π§ͺ Testing setup (optional)
- π§ͺ Unit tests: Separate test project targeting net8.0; mock platform services; test view models and services.
- π§ UI tests: Use frameworks like Playwright for Windows (desktop UI) or platform UI test tools; keep IDs consistent for selectors.
- π§± Architecture: Favor interfaces and pure logic in shared layer to maximize testability.
π Naming, organization, and tips
- π Feature-first folders: Group
Views/,ViewModels/,Services/by feature (e.g.,Features/Orders/...) for scale. - πͺ Partial classes: Split platform-specific bits from shared logic cleanly with partials and
#ifguards. - πΌοΈ Asset hygiene: Keep SVGs where possible; MAUI auto-generates densitiesβavoid manual platform duplication.
- π Permissions: Declare in platform manifests and wrap usage behind a shared service that handles prompts.
- β‘ Performance: Use compiled bindings, avoid heavy logic in
OnAppearing, and cache images/fonts.
β Quick checklist
- π¬ Entry wired:
MauiProgram.cssets fonts, handlers, DI. - πΊοΈ Shell set: Routes and navigation organized.
- πΌοΈ Resources mapped: Images, fonts, icons, splash in
Resources/. - π§© MVVM layered: Views, ViewModels, Services, Models separated.
- π₯οΈ Platforms: Manifests and platform-specific code in
Platforms/. - π§ͺ Tests: Unit tests for core logic; DI makes mocking easier.
| MAUI-index :👈 | 👉:XAML-in-MAUI |