Home › .NET MAUI › .NET MAUI rules
.NET MAUI rules
Cursor rules for .NET MAUI apps on .NET 10: MVVM with CommunityToolkit.Mvvm, Shell navigation, compiled bindings, DI.
Cursor.NET MAUI
How to use
Save this as .cursor/rules/maui.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
Note: Review and test before use. Provided as is, without warranty. See Terms.
.cursor/rules/maui.mdcDownload ---
description: .NET MAUI conventions
globs: ["**/*.cs","**/*.xaml"]
alwaysApply: false
---
# .NET MAUI (.NET 10)
- MVVM with `CommunityToolkit.Mvvm`: view models are `partial` classes deriving from `ObservableObject`, using `[ObservableProperty]` on partial properties and `[RelayCommand]` for commands (async commands get cancellation and `IsRunning`).
- No logic in code-behind beyond wiring; pages receive their view model through constructor DI.
- Register pages, view models, and services in `MauiProgram.CreateMauiApp()` (`AddTransient<OrdersPage>()`, `AddSingleton<IApiClient, ApiClient>()`).
- Every XAML page/template sets `x:DataType` so bindings are compiled and checked.
- Navigation with Shell routes (`Routing.RegisterRoute`, `await Shell.Current.GoToAsync("orders/detail", new Dictionary<string, object> { ["Order"] = order })`); receive with `IQueryAttributable` or `[QueryProperty]`.
- Lists use `CollectionView` (not `ListView`) with `DataTemplate`s; avoid nested scrolling.
- UI updates from background threads via `MainThread.BeginInvokeOnMainThread` only when needed; keep I/O async.
- Platform code in `Platforms/<platform>/` or partial classes; check permissions with `Permissions.RequestAsync<T>()`.
- Secrets in `SecureStorage`, settings in `Preferences`. HTTP via a typed `HttpClient` service.
- Styles and colors in `Resources/Styles`; support light/dark with `AppThemeBinding`.
## Done when
`dotnet build -f net10.0-android` (and the iOS/Windows targets you can build) succeeds with no XAML binding warnings, and unit tests for view models pass.