$npx -y skills add managedcode/dotnet-skills --skill winuiBuild 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 f
| 1 | # WinUI 3 and Windows App SDK |
| 2 | |
| 3 | ## Trigger On |
| 4 | |
| 5 | - building native modern Windows desktop UI on WinUI 3 |
| 6 | - integrating Windows App SDK features into a .NET app |
| 7 | - deciding between WinUI, WPF, WinForms, and MAUI for Windows work |
| 8 | - implementing MVVM patterns in Windows App SDK applications |
| 9 | |
| 10 | ## Workflow |
| 11 | |
| 12 | 1. **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. |
| 13 | 2. **Choose packaging model early** — packaged (MSIX) vs unpackaged differ materially for deployment, identity, and API access: |
| 14 | ```xml |
| 15 | <!-- Unpackaged: add to .csproj --> |
| 16 | <WindowsPackageType>None</WindowsPackageType> |
| 17 | ``` |
| 18 | 3. **Apply MVVM pattern** with the MVVM Toolkit — keep views dumb, logic in ViewModels: |
| 19 | ```csharp |
| 20 | public partial class ProductsViewModel : ObservableObject |
| 21 | { |
| 22 | [ObservableProperty] |
| 23 | private ObservableCollection<Product> _products = []; |
| 24 | |
| 25 | [ObservableProperty] |
| 26 | [NotifyCanExecuteChangedFor(nameof(DeleteCommand))] |
| 27 | private Product? _selectedProduct; |
| 28 | |
| 29 | [RelayCommand(CanExecute = nameof(CanDelete))] |
| 30 | private async Task DeleteAsync() |
| 31 | { |
| 32 | if (SelectedProduct is null) return; |
| 33 | await _productService.DeleteAsync(SelectedProduct.Id); |
| 34 | Products.Remove(SelectedProduct); |
| 35 | } |
| 36 | private bool CanDelete() => SelectedProduct is not null; |
| 37 | } |
| 38 | ``` |
| 39 | 4. **Use x:Bind for compiled bindings** — better performance and compile-time checking than `{Binding}`: |
| 40 | ```xml |
| 41 | <TextBlock Text="{x:Bind ViewModel.Title, Mode=OneWay}"/> |
| 42 | ``` |
| 43 | 5. **Wire DI through `Host.CreateDefaultBuilder`** — register services, ViewModels, and views. Resolve via `App.GetService<T>()`. |
| 44 | 6. **Implement navigation service** — map ViewModels to Pages by convention. See [references/patterns.md](references/patterns.md) for the full pattern. |
| 45 | 7. **Handle Windows App SDK features** — windowing (AppWindow), custom title bar, app lifecycle, notifications. |
| 46 | 8. **Always set `XamlRoot`** when showing ContentDialog — omitting this causes silent failures. |
| 47 | 9. **Validate on Windows targets** — behavior depends on runtime, packaging model, and Windows version. |
| 48 | |
| 49 | ## Current Upstream Notes |
| 50 | |
| 51 | - 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. |
| 52 | - For unpackaged apps, prefer `ApplicationData.GetForUnpackaged()` over registry or custom folder conventions when the app needs first-class app data storage. |
| 53 | - 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. |
| 54 | |
| 55 | ```mermaid |
| 56 | flowchart LR |
| 57 | A["Choose WinUI"] --> B["Select packaging model"] |
| 58 | B --> C["MVVM + DI setup"] |
| 59 | C --> D["Navigation and views"] |
| 60 | D --> E["Windows App SDK features"] |
| 61 | E --> F["Validate on target runtime"] |
| 62 | ``` |
| 63 | |
| 64 | ## Key Decisions |
| 65 | |
| 66 | | Decision | Guidance | |
| 67 | |----------|----------| |
| 68 | | Packaged vs unpackaged | Packaged (MSIX) for Store, auto-update, and full API access; unpackaged for simpler deployment | |
| 69 | | x:Bind vs Binding | Always prefer x:Bind — compiled, faster, type-safe | |
| 70 | | MVVM Toolkit attributes | Use `[ObservableProperty]`, `[RelayCommand]` to eliminate boilerplate | |
| 71 | | Navigation | Convention-based ViewModel→Page mapping via navigation service | |
| 72 | | Theming | Use `RequestedTheme` on root element; respect system theme by default | |
| 73 | |
| 74 | ## Deliver |
| 75 | |
| 76 | - modern Windows UI code with clear platform boundaries |
| 77 | - explicit deployment and packaging assumptions |
| 78 | - MVVM pattern with testable ViewModels |
| 79 | - cleaner interop between shared and Windows-specific layers |
| 80 | |
| 81 | ## Validate |
| 82 | |
| 83 | - WinUI is chosen for a real product reason, not defaulted to |
| 84 | - Windows App SDK dependencies are explicit in the project file |
| 85 | - packaging and runtime assumptions are tested on target |
| 86 | - x:Bind is used for compiled bindings throughout |
| 87 | - navigation and ContentDialog both work with correct XamlRoot |
| 88 | - custom title bar renders correctly on Windows 10 and 11 |
| 89 | |
| 90 | ## References |
| 91 | |
| 92 | - [references/patterns.md](references/patterns |