desktop-mvvm
Installation
SKILL.md
Desktop MVVM (.NET 10, CommunityToolkit.Mvvm)
Core Principles
- View models know nothing about the UI framework — No
Window,MessageBox,Dispatcher, orVisibilityin a view model. That keeps them unit-testable without a UI thread and portable between WPF, Avalonia, and MAUI. - Source generators over hand-written
INotifyPropertyChanged— CommunityToolkit.Mvvm (8.4.x, verified) generates the property, change notification, and command boilerplate at compile time. There's no reflection, so it stays trimming- and AOT-friendly. - Use partial properties, not fields — Since 8.4,
[ObservableProperty]goes onpartialproperties. From 8.4.1 that works on C# 14 with noLangVersion=preview. You get real properties that you can put attributes on and debug, instead of fields with magic names. - Async commands, never
async void—[RelayCommand]on aTask-returning method generates anIAsyncRelayCommand. It disables itself while running, surfaces exceptions, and supports cancellation. - Generic Host is the composition root — DI, configuration, logging, and
IHttpClientFactorywork the same as in ASP.NET Core. Views and view models are resolved from the container, nevernew-ed in code-behind.
Patterns
View Model with Generated Properties and Commands
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;