mvvm-toolkit

Implements CommunityToolkit.Mvvm source generators, commands, and validation for .NET ViewModels.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill mvvm-toolkit
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mvvm-toolkit
Source: https://github.com/github/awesome-copilot/tree/main/skills/mvvm-toolkit
Command: npx skills add https://github.com/github/awesome-copilot --skill mvvm-toolkit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires CommunityToolkit.Mvvm, and includes references (resource) components.

What problem does it solve?

Writing ViewModels with CommunityToolkit.Mvvm requires knowing the exact source-generator attributes, naming rules, and base classes, and small mistakes like forgetting partial or [NotifyCanExecuteChangedFor] cause confusing compile errors or silently broken UI bindings.

Core Features & Use Cases

  • Source Generator Guidance: Covers [ObservableProperty], [RelayCommand], [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], and [NotifyDataErrorInfo] with generated-code examples and naming rules.
  • Command Recipes: Provides sync, async, cancellable, concurrent, and error-surfacing RelayCommand/AsyncRelayCommand patterns ready to adapt.
  • Validation & Troubleshooting: Explains ObservableValidator with DataAnnotations, custom validation attributes, and a full MVVMTK0xxx diagnostic table.
  • Use Case: You are building a WinUI 3 settings form and need a ViewModel with validated inputs, a Save button that enables only when input is valid, and async save with cancellation — this Skill provides the exact attribute combination and code pattern.

Quick Start

Ask the AI to create a CommunityToolkit.Mvvm ViewModel with an observable property, an async save command with CanExecute, and validation attributes for a registration form.

Frequently Asked Questions about mvvm-toolkit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use [ObservableProperty] in CommunityToolkit.Mvvm?▼

Apply [ObservableProperty] to a private field inside a partial class inheriting from ObservableObject. The generator creates a public property with change notification, so a field named `name` becomes a `Name` property with optional OnNameChanged hooks.

How do I create an async RelayCommand with cancellation?▼

Annotate an async Task method that accepts a CancellationToken with [RelayCommand(IncludeCancelCommand = true)]. The toolkit generates an IAsyncRelayCommand plus a paired cancel command whose CanExecute tracks the running state.

Why does MVVMTK0008 appear when using [ObservableProperty]?▼

MVVMTK0008 means the containing class, or an enclosing type for nested classes, is not declared partial. The source generator emits a sibling partial declaration, so every level of the type hierarchy must include the partial keyword.

What is the difference between ObservableObject, ObservableValidator, and ObservableRecipient?▼

ObservableObject is the default base providing INotifyPropertyChanged and SetProperty. ObservableValidator adds INotifyDataErrorInfo for form validation, and ObservableRecipient adds IMessenger integration. C# single inheritance means you pick one and compose the others.

Why does my Save button stay disabled after typing in a field?▼

The command's CanExecute is not re-evaluated when the bound property changes. Add [NotifyCanExecuteChangedFor(nameof(SaveCommand))] to the observable field so the generator calls NotifyCanExecuteChanged automatically on every change.

Does CommunityToolkit.Mvvm work with WPF, MAUI, and Avalonia?▼

Yes, the toolkit targets netstandard2.0, netstandard2.1, and net6.0+, so the same ViewModel patterns work across WPF, WinUI 3, MAUI, Uno Platform, and Avalonia. Only the XAML binding syntax and app bootstrap differ per framework.