1---2name: dotnet-winui3description: Build or review WinUI 3 applications with the Windows App SDK, including MVVM patterns, packaging decisions, navigation, theming, windowing, and interop boundaries with other .NET stacks. Use when building modern Windows-native desktop UI.4---56# WinUI 3 and Windows App SDK78## Trigger On910- building native modern Windows desktop UI on WinUI 311- integrating Windows App SDK features into a .NET app12- deciding between WinUI, WPF, WinForms, and MAUI for Windows work13- implementing MVVM patterns in Windows App SDK applications1415## Workflow16171. **Confirm WinUI is the right choice** — use when modern Windows-native UI, Fluent Design, and Windows App SDK capabilities are needed. For cross-platform, consider MAUI instead.182. **Choose packaging model early** — packaged (MSIX) vs unpackaged differ materially for deployment, identity, and API access:19 ```xml20 <!-- Unpackaged: add to .csproj -->21 <WindowsPackageType>None</WindowsPackageType>22 ```233. **Apply MVVM pattern** with the MVVM Toolkit — keep views dumb, logic in ViewModels:24 ```csharp25 public partial class ProductsViewModel : ObservableObject26 {27 [ObservableProperty]28 private ObservableCollection<Product> _products = [];2930 [ObservableProperty]31 [NotifyCanExecuteChangedFor(nameof(DeleteCommand))]32 private Product? _selectedProduct;3334 [RelayCommand(CanExecute = nameof(CanDelete))]35 private async Task DeleteAsync()36 {37 if (SelectedProduct is null) return;38 await _productService.DeleteAsync(SelectedProduct.Id);39 Products.Remove(SelectedProduct);40 }41 private bool CanDelete() => SelectedProduct is not null;42 }43 ```444. **Use x:Bind for compiled bindings** — better performance and compile-time checking than `{Binding}`:45 ```xml46 <TextBlock Text="{x:Bind ViewModel.Title, Mode=OneWay}"/>47 ```485. **Wire DI through `Host.CreateDefaultBuilder`** — register services, ViewModels, and views. Resolve via `App.GetService<T>()`.496. **Implement navigation service** — map ViewModels to Pages by convention. See references/patterns.md for the full pattern.507. **Handle Windows App SDK features** — windowing (AppWindow), custom title bar, app lifecycle, notifications.518. **Always set `XamlRoot`** when showing ContentDialog — omitting this causes silent failures.529. **Validate on Windows targets** — behavior depends on runtime, packaging model, and Windows version.5354```mermaid55flowchart LR56 A["Choose WinUI"] --> B["Select packaging model"]57 B --> C["MVVM + DI setup"]58 C --> D["Navigation and views"]59 D --> E["Windows App SDK features"]60 E --> F["Validate on target runtime"]61```6263## Key Decisions6465| Decision | Guidance |66|----------|----------|67| Packaged vs unpackaged | Packaged (MSIX) for Store, auto-update, and full API access; unpackaged for simpler deployment |68| x:Bind vs Binding | Always prefer x:Bind — compiled, faster, type-safe |69| MVVM Toolkit attributes | Use `[ObservableProperty]`, `[RelayCommand]` to eliminate boilerplate |70| Navigation | Convention-based ViewModel→Page mapping via navigation service |71| Theming | Use `RequestedTheme` on root element; respect system theme by default |7273## Deliver7475- modern Windows UI code with clear platform boundaries76- explicit deployment and packaging assumptions77- MVVM pattern with testable ViewModels78- cleaner interop between shared and Windows-specific layers7980## Validate8182- WinUI is chosen for a real product reason, not defaulted to83- Windows App SDK dependencies are explicit in the project file84- packaging and runtime assumptions are tested on target85- x:Bind is used for compiled bindings throughout86- navigation and ContentDialog both work with correct XamlRoot87- custom title bar renders correctly on Windows 10 and 118889## References9091- references/patterns.md - WinUI 3 patterns including MVVM, navigation services, DI setup, windowing, theming, dialogs, and lifecycle handling92- references/anti-patterns.md - common WinUI mistakes with explanations and corrections