Winui

From managedcode/dotnet-skills · View interactive version

Winui is an AI agent skill from the GitHub repository managedcode/dotnet-skills. 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

How to use this skill

Skill file

WinUI 3 and Windows App SDK

Trigger On

Workflow

  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.
  2. Choose packaging model early — packaged (MSIX) vs unpackaged differ materially for deployment, identity, and API access:

```xml

<!-- Unpackaged: add to .csproj -->

<WindowsPackageType>None</WindowsPackageType>

```

  1. Apply MVVM pattern with the MVVM Toolkit — keep views dumb, logic in ViewModels:

```csharp

public partial class ProductsViewModel : ObservableObject

{

[ObservableProperty]

private ObservableCollection<Product> _products = [];

[ObservableProperty]

[NotifyCanExecuteChangedFor(nameof(DeleteCommand))]

private Product? _selectedProduct;

[RelayCommand(CanExecute = nameof(CanDelete))]

private async Task DeleteAsync()

{

if (SelectedProduct is null) return;

await _productService.DeleteAsync(SelectedProduct.Id);

Products.Remove(SelectedProduct);

}

private bool CanDelete() => SelectedProduct is not null;

}

```

  1. Use x:Bind for compiled bindings — better performance and compile-time checking than {Binding}:

```xml

<TextBlock Text="{x:Bind ViewModel.Title, Mode=OneWay}"/>

```

  1. Wire DI through Host.CreateDefaultBuilder — register services, ViewModels, and views. Resolve via App.GetService<T>().
  2. Implement navigation service — map ViewModels to Pages by convention. See references/patterns.md for the full pattern.
  3. Handle Windows App SDK features — windowing (AppWindow), custom title bar, app lifecycle, notifications.
  4. Always set XamlRoot when showing ContentDialog — omitting this causes silent failures.
  5. Validate on Windows targets — behavior depends on runtime, packaging model, and Windows version.

Current Upstream Notes

flowchart LR
  A["Choose WinUI"] --> B["Select packaging model"]
  B --> C["MVVM + DI setup"]
  C --> D["Navigation and views"]
  D --> E["Windows App SDK features"]
  E --> F["Validate on target runtime"]

Key Decisions

| Decision | Guidance |

|----------|----------|

| Packaged vs unpackaged | Packaged (MSIX) for Store, auto-update, and full API access; unpackaged for simpler deployment |

| x:Bind vs Binding | Always prefer x:Bind — compiled, faster, type-safe |

| MVVM Toolkit attributes | Use [ObservableProperty], [RelayCommand] to eliminate boilerplate |

| Navigation | Convention-based ViewModel→Page mapping via navigation service |

| Theming | Use RequestedTheme on root element; respect system theme by default |

Deliver

Validate

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.