Skills

Mvvm

Implement the Model-View-ViewModel pattern in .NET applications with proper separation...

Install

npx skills add managedcode/dotnet-skills --skill mvvm -g -a claude-code -y
Category
Design
Updated
6d ago
License
MIT
Context cost
Mediumabout 2,567 tokens
Runs scripts
No, instructions only

What it does

Implement the Model-View-ViewModel pattern in .NET applications with proper separation of concerns, data binding, commands, and testable ViewModels using MVVM Toolkit. USE FOR: implementing UI separation with Model-View-ViewModel; using MVVM Toolkit (CommunityToolkit.Mvvm) for ViewModels; designing testable UI architecture. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.

MVVM Pattern for .NET

Trigger On

  • implementing UI separation with Model-View-ViewModel
  • using MVVM Toolkit (CommunityToolkit.Mvvm) for ViewModels
  • designing testable UI architecture
  • handling commands, property changes, and messaging
  • choosing between MVVM frameworks

Documentation

References

See detailed examples in the references/ folder:

Core Concepts

ComponentResponsibilityExample
ModelBusiness logic and dataProduct, Order, User
ViewUI presentation (XAML/Razor)ProductPage.xaml
ViewModelUI logic and stateProductViewModel

Workflow

  1. Keep Views dumb, no business logic in code-behind
  2. Use data binding, connect View to ViewModel properties
  3. Commands for actions, handle user interactions via ICommand
  4. Inject dependencies, services go into ViewModel constructors
  5. Test ViewModels, they should be unit testable without UI

MVVM Toolkit Setup

<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />

ViewModel Patterns

Basic ViewModel with Source Generators

public partial class ProductViewModel(IProductService productService) : ObservableObject
{
    [ObservableProperty]
    private string _name = string.Empty;
Read the whole SKILL.md on GitHub

More in Design