dotnet-mvvm

Implement the MVVM pattern in .NET applications using MVVM Toolkit source generators.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-mvvm-zhenpenglai
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-mvvm
Source: https://github.com/zhenpengLai/myuseskill/tree/main/dotnet-mvvm
Command: npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-mvvm-zhenpenglai

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building .NET UI applications often leads to tangled code-behind, untestable logic, and tight coupling between Views and business logic. This Skill guides the implementation of the Model-View-ViewModel pattern with the CommunityToolkit.Mvvm library so ViewModels stay testable and Views stay free of business logic. ## Core Features & Use Cases - Source-Generated ViewModels: Use ObservableProperty, RelayCommand, and NotifyCanExecuteChangedFor attributes to eliminate boilerplate INotifyPropertyChanged code. - Messaging, Validation, and DI: Apply WeakReferenceMessenger for loose coupling, ObservableValidator for data annotation validation, and constructor injection for services. - Anti-Pattern Guidance: Identify and fix common mistakes like logic in code-behind, God ViewModels, and ViewModels referencing View types. - Use Case: When building a WPF, MAUI, WinUI, or Avalonia product page, generate a ProductViewModel with observable properties, async save commands with CanExecute logic, and unit tests that run without any UI. ## Quick Start Ask the AI to create a testable ViewModel with observable properties and RelayCommands for your .NET page using the MVVM Toolkit.

Frequently Asked Questions about dotnet-mvvm

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

FAQPage Schema
How do I create a ViewModel with MVVM Toolkit in .NET?▼

Inherit from ObservableObject and annotate private fields with [ObservableProperty] to auto-generate properties. Add methods annotated with [RelayCommand] to generate ICommand properties, and install the CommunityToolkit.Mvvm NuGet package.

MVVM Toolkit vs Prism vs MVVMLight for .NET?▼

MVVM Toolkit offers source generators and is lightweight and actively maintained, but lacks built-in DI and navigation. Prism includes DI and navigation but is heavier. MVVMLight is deprecated and should be avoided for new projects.

Does MVVM Toolkit work with MAUI, WPF, and WinUI?▼

Yes, CommunityToolkit.Mvvm works across WPF, MAUI, WinUI, Uno Platform, Avalonia, and Blazor because it is platform-agnostic. It provides only ViewModel infrastructure, so navigation and dialogs require platform-specific services.

How do I validate user input in a ViewModel?▼

Inherit from ObservableValidator and add [NotifyDataErrorInfo] plus data annotation attributes like [Required] and [MinLength] to observable properties. Call ValidateAllProperties() before saving and check HasErrors to gate command execution.

Why is my RelayCommand not updating its CanExecute state?▼

The command does not automatically re-evaluate when properties change. Add [NotifyCanExecuteChangedFor(nameof(YourCommand))] to the property that affects the CanExecute condition so the command raises CanExecuteChanged.

How do ViewModels communicate without tight coupling?▼

Use WeakReferenceMessenger to send record-based messages between ViewModels. The receiving ViewModel inherits from ObservableRecipient, sets IsActive = true, and registers a handler in OnActivated.