/dotnet-desktop-development:mvvm-toolkitfrom dotnet-desktop-development
Guides authoring and reviewing CommunityToolkit.Mvvm 8.x ViewModels with source generators, observable properties, commands, validation, and base-class selection for WPF, WinUI 3, MAUI, Uno, and Avalonia.
Ships in dotnet-desktop-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Author or review CommunityToolkit.Mvvm 8.x ViewModels by choosing the right base class, applying source-generator attributes correctly, wiring commands and validation, and avoiding generator diagnostics and notification bugs.
Install the toolkit package in the project that owns the ViewModels:
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
</ItemGroup>
Targets include netstandard2.0, netstandard2.1, and net6.0+. The package works on .NET, .NET Framework, and Mono. Source generators ship with the NuGet package; no extra analyzer reference is required.
using CommunityToolkit.Mvvm.ComponentModel; // ObservableObject, ObservableValidator, ObservableRecipient, [ObservableProperty]
using CommunityToolkit.Mvvm.Input; // [RelayCommand], RelayCommand, AsyncRelayCommand
Every type that uses [ObservableProperty] or [RelayCommand], and every enclosing type if nested, must be declared partial. Without partial, generators emit MVVMTK0008 or MVVMTK0042.
| Attribute or API | Applied to | Generates or does |
|---|---|---|
[ObservableProperty] | private field | Public INotifyPropertyChanged property plus OnXxxChanging and OnXxxChanged partial-method hooks. |
[NotifyPropertyChangedFor(nameof(Other))] | observable field | Also raises PropertyChanged for a dependent property. |
[NotifyCanExecuteChangedFor(nameof(MyCommand))] | observable field | Calls MyCommand.NotifyCanExecuteChanged() when the field changes. |
[NotifyDataErrorInfo] | observable field on ObservableValidator | Calls ValidateProperty(value) from the generated setter. |
[NotifyPropertyChangedRecipients] | observable field on ObservableRecipient | Calls Broadcast(old, new) after the change. |
[RelayCommand] | instance method | Lazy RelayCommand or AsyncRelayCommand, exposed as IRelayCommand or IAsyncRelayCommand. |
[RelayCommand(CanExecute = nameof(CanX))] | instance method | Wires CanExecute to a method or property. |
[RelayCommand(IncludeCancelCommand = true)] | async method with CancellationToken | Generates XxxCancelCommand. |
[RelayCommand(AllowConcurrentExecutions = true)] | async method | Allows queued or parallel invocations; default disables while running. |
[RelayCommand(FlowExceptionsToTaskScheduler = true)] | async method | Surfaces exceptions through ExecutionTask instead of awaiting and rethrowing. |
[property: SomeAttr] | observable field or [RelayCommand] method | Forwards SomeAttr to the generated property, such as [JsonIgnore]. |
Naming rules:
| Source name | Generated name |
|---|---|
field name, _name, or m_name | property Name |
method LoadAsync | command LoadCommand |
method OnSave | command SaveCommand |
Simple generated property:
public partial class ContactViewModel : ObservableObject
{
[ObservableProperty]
private string? name;
}
Partial hooks are optional and have zero runtime cost when unimplemented. Both (value) and (oldValue, newValue) overloads are available.
[ObservableProperty]
private string? name;
partial void OnNameChanged(string? value) =>
Logger.LogInformation("Name changed to {Name}", value);
Use dependent notifications and command invalidation together when editable fields drive both computed display and button state.
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private string? firstName;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private string? lastName;
public string FullName => $"{FirstName} {LastName}".Trim();
Wrap non-observable models with SetProperty and a static lambda to avoid captured-state allocations.
public sealed class ObservableUser(User user) : ObservableObject
{
public string Name
{
get => user.Name;
set => SetProperty(user.Name, value, user, (u, n) => u.Name = n);
}
}
Use [RelayCommand] for most command properties. Reach for manual RelayCommand or AsyncRelayCommand constructors only when you must own the command lifetime explicitly or compose commands from non-trivial sources.
[RelayCommand]
private void Refresh() => Items.Reset();
[RelayCommand]
private async Task LoadAsync()
{
foreach (var item in await service.GetItemsAsync())
Items.Add(item);
}
[RelayCommand(IncludeCancelCommand = true)]
private async Task DownloadAsync(CancellationToken token)
{
await using var stream = await http.GetStreamAsync(url, token);
}
[RelayCommand(CanExecute = nameof(CanSave))]
private Task SaveAsync() => repo.SaveAsync(Name!);
private bool CanSave() => !string.IsNullOrWhiteSpace(Name);
| Base class | Use when |
|---|---|
ObservableObject | Default: INotifyPropertyChanged, INotifyPropertyChanging, SetProperty overloads, and SetPropertyAndNotifyOnCompletion for Task properties. |
ObservableValidator | The ViewModel needs INotifyDataErrorInfo, forms, or settings validation. |
ObservableRecipient | The ViewModel sends or receives IMessenger messages. |
C# is single-inheritance. ObservableValidator and ObservableRecipient both extend ObservableObject, so combine validation and messaging through composition, such as injecting IMessenger into an ObservableValidator.
Use ObservableValidator plus [NotifyDataErrorInfo] and System.ComponentModel.DataAnnotations attributes for generated validation setters.
using System.ComponentModel.DataAnnotations;
public sealed partial class RegistrationViewModel : ObservableValidator
{
[ObservableProperty]
[NotifyDataErrorInfo]
[Required, MinLength(2), MaxLength(100)]
private string? name;
[ObservableProperty]
[NotifyDataErrorInfo]
[Required, EmailAddress]
private string? email;
[RelayCommand]
private void Submit()
{
ValidateAllProperties();
if (HasErrors) return;
}
}
Other validation APIs: TrySetProperty, ValidateProperty(value, name), ClearAllErrors(), and GetErrors(propertyName). Custom rules can use [CustomValidation] methods or custom ValidationAttribute subclasses.
| Pitfall | Why it breaks | Fix |
|---|---|---|
Missing partial on a class or enclosing type | Generators cannot emit members; MVVMTK0008 / MVVMTK0042. | Mark each type in the nesting chain partial. |
[ObservableProperty] private string Name; | PascalCase field collides with generated property. | Use name, _name, or m_name. |
async void method with [RelayCommand] | It becomes a sync RelayCommand; exceptions are unobserved. | Return Task so the generator creates IAsyncRelayCommand. |
Missing [NotifyCanExecuteChangedFor] | Buttons remain disabled even when CanSave() changes. | Add the attribute to every observable field that affects CanExecute. |
Mutating the same reference held by an [ObservableProperty] field | EqualityComparer<T>.Default sees the same reference and no notification fires. | Replace the instance or expose observable child properties. |
Read references only when the current task needs deeper detail.
references/source-generators.md: full source-generator attribute reference and generated-code samples.references/relaycommand-cookbook.md: sync, async, cancellable, concurrency, and error-surfacing recipes.references/validation.md: full ObservableValidator surface area.references/end-to-end-walkthrough.md: Notes app sample with DI wiring, View code-behind, XAML, unit tests, and [NotifyCanExecuteChangedFor].references/troubleshooting.md: MVVMTK0xxx diagnostics and additional pitfalls.| Name | Type | Use it when |
|---|---|---|
mvvm-toolkit-messenger | skill | The task centers on IMessenger pub/sub patterns. |
mvvm-toolkit-di | skill | The task centers on Microsoft.Extensions.DependencyInjection wiring. |
Use this two-pane notes pattern when the user needs a compact sample that combines generators, commands, messenger calls, and [NotifyCanExecuteChangedFor].
public sealed partial class NoteViewModel(INotesService notes, IMessenger messenger)
: ObservableRecipient(messenger)
{
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
[NotifyCanExecuteChangedFor(nameof(DeleteCommand))]
private string? filename;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private string? text;
[RelayCommand(CanExecute = nameof(CanSave))]
private Task SaveAsync()
{
Messenger.Send(new NoteSavedMessage(Filename!));
return notes.SaveAsync(Filename!, Text!);
}
[RelayCommand(CanExecute = nameof(CanDelete))]
private Task DeleteAsync() => notes.DeleteAsync(Filename!);
private bool CanSave() =>
!string.IsNullOrWhiteSpace(Filename) && !string.IsNullOrEmpty(Text);
private bool CanDelete() => !string.IsNullOrWhiteSpace(Filename);
}
Preserve terminology around hooks and command behavior: single-arg, two-arg, Async, queued/parallel, allocation-free, to-end, true, and messenger pub/sub** patterns.
## MVVM Toolkit result
**Status:** implemented | reviewed | blocked
**Target:** `<ViewModel or file>`
**Base class:** `ObservableObject | ObservableValidator | ObservableRecipient`
### Generated members used
| Source | Generated member | Notes |
| --- | --- | --- |
| `[ObservableProperty] private <field>;` | `<Property>` | `<dependent notifications or validation>` |
| `[RelayCommand] <method>` | `<MethodCommand>` | `<CanExecute/cancellation/concurrency>` |
### Validation
- `partial` declarations: pass | fail
- Commands update `CanExecute`: pass | fail | not applicable
- Validation APIs: pass | fail | not applicable
partial.name, _name, or m_name naming and do not collide with generated properties.Task, not async void.CanExecute include [NotifyCanExecuteChangedFor].ObservableValidator and call ValidateAllProperties() before submit when needed.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
mvvm, viewmodel, source-generators, observable-properties, relaycommand
9 skills in this plugin
/dotnet-timezoneResolve .NET and C# timezone questions with TimeZoneInfo, DateTimeOffset, TimeZoneConverter, NodaTime, UTC conversion, daylight saving time, scheduling, Windows and IANA timezone IDs, location lookup, and copy-paste-ready code. Use this skill when a .NET user needs the timezone for a city, address, region, or country, or asks about cross-platform timezone handling./msstore-cliUse Microsoft Store Developer CLI (msstore) to configure Partner Center credentials, list Store apps, package and publish Windows submissions, check status, manage package flights, gradual rollouts, and CI/CD publishing for Windows App SDK/WinUI, UWP, .NET MAUI, Flutter, Electron, React Native, and PWA apps. Use when asked to configure Store credentials, publish to Microsoft Store, check submission status, or automate Store releases./mvvm-toolkit-diWire CommunityToolkit.Mvvm ViewModels into Microsoft.Extensions.DependencyInjection for XAML apps. Use this skill when standing up a .NET Generic Host composition root for WPF, WinUI 3, .NET MAUI, Uno, or Avalonia; choosing Singleton, Transient, or Scoped lifetimes; registering IMessenger; resolving ViewModels in Views; using keyed services; adding test seams; or replacing legacy Ioc.Default service-locator code./mvvm-toolkit-messengerConfigure CommunityToolkit.Mvvm Messenger pub/sub for decoupled ViewModel communication. Use this skill when users ask to send messages between ViewModels, choose WeakReferenceMessenger vs StrongReferenceMessenger, use IRecipient<TMessage>, RequestMessage<T>, AsyncRequestMessage<T>, CollectionRequestMessage<T>, ValueChangedMessage<T>, channel tokens, or ObservableRecipient activation in WPF, WinUI 3, .NET MAUI, Uno, or Avalonia./nuget-managerManage NuGet packages safely in .NET projects and solutions using the `dotnet` CLI. Use this skill when adding, removing, or updating package versions, verifying `PACKAGE_NAME` availability, working with `Directory.Packages.props`, or deciding when direct `.csproj` edits are allowed./system-commandline-cliAdd, modify, or review .NET CLI commands built with System.CommandLine by applying project command-base conventions, options and arguments, SetAction handlers, RootCommand registration, global options, dependency injection, validation, naming, and destructive-operation confirmation. Use when the user mentions System.CommandLine, CommandBase, ParseResult, SetAction, RootCommand, subcommands, or asks to add a CLI verb.npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin dotnet-desktop-developmentOther plugins' skills for the same job