1---2name: 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 FOR: building native modern Windows desktop UI on WinUI 3; integrating Windows App SDK features into a .NET app; deciding between WinUI, WPF, WinForms, and MAUI for Windows. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.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](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## Current Upstream Notes5556- Windows App SDK `2.3.1` adds schema-constrained Phi Silica JSON output, `XamlOptionalChanges`, ARM64EC support for Windows ML, Video Super Resolution improvements, and opt-in XAML startup/style/resource-lookup optimizations.57- Windows App SDK `1.8.11` is the current 1.8 servicing patch. It restores focus after storage pickers, fixes MRT fallback resolution, and isolates runtime base-directory environment state; retest picker return focus, resource fallback, and side-by-side runtime activation when maintaining the 1.8 line.58- For unpackaged apps, prefer `ApplicationData.GetForUnpackaged()` over registry or custom folder conventions when the app needs first-class app data storage.59- When upgrading to 2.3.1, retest unpackaged `LocalSettings`, background tasks, side-placement flyouts, `MediaPlayerPresenter` device loss, popup pointer replay, `ItemsRepeater` layouts, Windows ML, and any opted-in XAML change IDs.6061```mermaid62flowchart LR63 A["Choose WinUI"] --> B["Select packaging model"]64 B --> C["MVVM + DI setup"]65 C --> D["Navigation and views"]66 D --> E["Windows App SDK features"]67 E --> F["Validate on target runtime"]68```6970## Key Decisions7172| Decision | Guidance |73|----------|----------|74| Packaged vs unpackaged | Packaged (MSIX) for Store, auto-update, and full API access; unpackaged for simpler deployment |75| x:Bind vs Binding | Always prefer x:Bind — compiled, faster, type-safe |76| MVVM Toolkit attributes | Use `[ObservableProperty]`, `[RelayCommand]` to eliminate boilerplate |77| Navigation | Convention-based ViewModel→Page mapping via navigation service |78| Theming | Use `RequestedTheme` on root element; respect system theme by default |7980## Deliver8182- modern Windows UI code with clear platform boundaries83- explicit deployment and packaging assumptions84- MVVM pattern with testable ViewModels85- cleaner interop between shared and Windows-specific layers8687## Validate8889- WinUI is chosen for a real product reason, not defaulted to90- Windows App SDK dependencies are explicit in the project file91- packaging and runtime assumptions are tested on target92- x:Bind is used for compiled bindings throughout93- navigation and ContentDialog both work with correct XamlRoot94- custom title bar renders correctly on Windows 10 and 119596## References9798- [references/patterns.md](references/patterns.md) - WinUI 3 patterns including MVVM, navigation services, DI setup, windowing, theming, dialogs, and lifecycle handling99- [references/anti-patterns.md](references/anti-patterns.md) - common WinUI mistakes with explanations and corrections