
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- Repository
- managedcode/dotnet-skills500
- 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:
patterns.md, ViewModel, command, navigation, and state patternsanti-patterns.md, Common mistakes and how to fix them
Core Concepts
| Component | Responsibility | Example |
|---|---|---|
| Model | Business logic and data | Product, Order, User |
| View | UI presentation (XAML/Razor) | ProductPage.xaml |
| ViewModel | UI logic and state | ProductViewModel |
Workflow
- Keep Views dumb, no business logic in code-behind
- Use data binding, connect View to ViewModel properties
- Commands for actions, handle user interactions via ICommand
- Inject dependencies, services go into ViewModel constructors
- 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;


