Attribution: Sourced from github/awesome-copilot by GitHub Community, licensed MIT. Modified for this collection.
CommunityToolkit.Mvvm (core)
Use this skill when authoring or reviewing ViewModels, properties,
commands, or validation in apps that use CommunityToolkit.Mvvm 8.x.
Companion skills. Load
mvvm-toolkit-messengerforIMessenger
pub/sub patterns. Load
mvvm-toolkit-difor
Microsoft.Extensions.DependencyInjectionintegration.
Quick recap. On CommunityToolkit.Mvvm 8.4+, use an
[ObservableProperty]partial property when the project uses the .NET 9
SDK and C# preview language mode required by Toolkit 8.4;
keep the field form for older language versions. WinUI 3 AOT requires the
partial-property form. Use
[RelayCommand]on instance methods; inherit from
ObservableObject(orObservableValidatorfor input forms,
ObservableRecipientwhen usingIMessenger).
Package & setup
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
</ItemGroup>
Targets: netstandard2.0, netstandard2.1, net6.0+. Works on .NET, .NET
Framework, Mono. Source generators ship in the same NuGet — no extra
analyzer reference required.
Namespaces:
using CommunityToolkit.Mvvm.ComponentModel; // ObservableObject, [ObservableProperty]
using CommunityToolkit.Mvvm.Input; // [RelayCommand], RelayCommand, AsyncRelayCommand
Universal rule. Every type that uses
[ObservableProperty]or
[RelayCommand]— and every enclosing type, if nested — must be
declared
partial. A non-partial containing type triggersMVVMTK0008.
MVVMTK0042instead recommends converting an observable field to a
partial property;
MVVMTK0045warns that the field form is not AOT-safe
in WinRT scenarios such as WinUI 3.
Source generators cheat sheet
| Attribute | Applied to | Generates |
|-----------|-----------|-----------|
| [ObservableProperty] | partial property (.NET 9 SDK + C# preview for Toolkit 8.4) or field | Implements the property/notification setter + OnXxxChanging/OnXxxChanged partial-method hooks |
| [NotifyPropertyChangedFor(nameof(Other))] | observable property or field | Also raises PropertyChanged for the listed property |
| [NotifyCanExecuteChangedFor(nameof(MyCommand))] | observable property or field | Calls MyCommand.NotifyCanExecuteChanged() on change |
| [NotifyDataErrorInfo] | observable property or field on ObservableValidator | Calls ValidateProperty(value) from the setter |
| [NotifyPropertyChangedRecipients] | observable property or field on ObservableRecipient | Broadcast(old, new) after the change |
| [RelayCommand] | instance method | Lazy RelayCommand / AsyncRelayCommand exposed as IRelayCommand / IAsyncRelayCommand |
| [RelayCommand(CanExecute = nameof(CanX))] | instance method | Wires CanExecute to a method or property |
| [RelayCommand(IncludeCancelCommand = true)] | async method with CancellationToken | Also generates XxxCancelCommand |
| [RelayCommand(AllowConcurrentExecutions = true)] | async method | Allows queued/parallel invocations (default disables while running) |
| [RelayCommand(FlowExceptionsToTaskScheduler = true)] | async method | Surfaces exceptions via ExecutionTask instead of awaiting and rethrowing |
| [property: SomeAttr] | observable field or [RelayCommand] method | Forwards SomeAttr onto the generated property (e.g., [JsonIgnore]) |
Naming. Field name / _name / m_name → Name. Method LoadAsync →
LoadCommand (the Async suffix is stripped; a leading On is also
stripped).