desktop-mvvm

Installation
SKILL.md

Desktop MVVM (.NET 10, CommunityToolkit.Mvvm)

Core Principles

  1. View models know nothing about the UI framework — No Window, MessageBox, Dispatcher, or Visibility in a view model. That keeps them unit-testable without a UI thread and portable between WPF, Avalonia, and MAUI.
  2. 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.
  3. Use partial properties, not fields — Since 8.4, [ObservableProperty] goes on partial properties. From 8.4.1 that works on C# 14 with no LangVersion=preview. You get real properties that you can put attributes on and debug, instead of fields with magic names.
  4. Async commands, never async void — [RelayCommand] on a Task-returning method generates an IAsyncRelayCommand. It disables itself while running, surfaces exceptions, and supports cancellation.
  5. Generic Host is the composition root — DI, configuration, logging, and IHttpClientFactory work the same as in ASP.NET Core. Views and view models are resolved from the container, never new-ed in code-behind.

Patterns

View Model with Generated Properties and Commands

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Installs
40
GitHub Stars
801
First Seen
1 day ago