# desktop-mvvm

The desktop-mvvm skill implements MVVM for .NET desktop apps with source generators in Claude Code.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 758 installs · ★ 845 repo stars
- Author: codewithmukesh
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/desktop-mvvm/SKILL.md
- Updated: 2026-08-07
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/desktop-mvvm

## What it does

The skill configures the MVVM pattern for WPF, Avalonia, WinForms, and MAUI using CommunityToolkit.Mvvm 8.4+ source generators. It generates properties with `[ObservableProperty]` and async commands with `[RelayCommand]` to eliminate boilerplate notification code.

The setup relies on Generic Host for dependency injection and keeps view models decoupled from UI frameworks for unit testing. The agent handles UI-thread dispatching and progress reporting without framework clutter.

The code requires .NET 10 and CommunityToolkit.Mvvm 8.4+.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill desktop-mvvm -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/desktop-mvvm/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/desktop-mvvm/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill desktop-mvvm -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/desktop-mvvm/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill desktop-mvvm -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/desktop-mvvm/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install codewithmukesh/dotnet-claude-kit skills/desktop-mvvm
```

2. **Manually: put the files in place**
- File: `.github/skills/desktop-mvvm/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill desktop-mvvm -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/codewithmukesh/dotnet-claude-kit --path skills/desktop-mvvm
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/desktop-mvvm/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill desktop-mvvm -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/desktop-mvvm/SKILL.md

## When to use it
- generate observable properties and change notifications with `[ObservableProperty]`
- create async commands with cancellation and execution locks via `[RelayCommand]`
- set up Generic Host and dependency injection in a desktop app
- implement view-model-first navigation
- dispatch background operations to the UI thread safely

## Example prompts
- Set up MVVM with CommunityToolkit.Mvvm for a WPF project
- Add an async command to OrdersViewModel with cancellation support
- Configure Generic Host in `App.xaml.cs` for DI

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 75d83ac12d8ddec7.

BEGIN THIRD-PARTY FILE 75d83ac12d8ddec7
````text
---
name: desktop-mvvm
description: >
  MVVM for .NET desktop apps (WPF, Avalonia, WinForms, MAUI) with
  CommunityToolkit.Mvvm 8.4+ source generators: [ObservableProperty] partial
  properties, [RelayCommand] async commands, Generic Host + DI, UI-thread
  dispatching, navigation, messaging, and testable view models. Load when the
  user mentions "MVVM", "ViewModel", "WPF", "desktop app", "ObservableProperty",
  "RelayCommand", "ICommand", "INotifyPropertyChanged", "Dispatcher", or "UI thread".
---

# Desktop MVVM (.NET 10, CommunityToolkit.Mvvm)

## Core Principles

1. **View models know nothing about the UI framework** — No `Window`, `MessageBox`, `Dispatcher`, or `Visibility` in a view model. That keeps them unit-testable without a UI thread and portable between WPF, Avalonia, and MAUI.
2. **Source generators over hand-written `INotifyPropertyChanged`** — CommunityToolkit.Mvvm (8.4.x, verified) generates the property, change notification, and command boilerplate at compile time. There's no reflection, so it stays trimming- and AOT-friendly.
3. **Use partial properties, not fields** — Since 8.4, `[ObservableProperty]` goes on `partial` properties. From 8.4.1 that works on C# 14 with no `LangVersion=preview`. You get real properties that you can put attributes on and debug, instead of fields with magic names.
4. **Async commands, never `async void`** — `[RelayCommand]` on a `Task`-returning method generates an `IAsyncRelayCommand`. It disables itself while running, surfaces exceptions, and supports cancellation.
5. **Generic Host is the composition root** — DI, configuration, logging, and `IHttpClientFactory` work the same as in ASP.NET Core. Views and view models are resolved from the container, never `new`-ed in code-behind.

## Patterns

### View Model with Generated Properties and Commands

```csharp
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

public sealed partial class OrdersViewModel(IOrderService orders, TimeProvider clock) : ObservableObject
{
    [ObservableProperty]
    [NotifyCanExecuteChangedFor(nameof(SaveCommand))]
    public partial string? CustomerName { get; set; }

    [ObservableProperty]
    public partial OrderRow? SelectedOrder { get; set; }

    public ObservableCollection<OrderRow> Orders { get; } = [];

    // Generates LoadCommand (IAsyncRelayCommand) + LoadCancelCommand
    [RelayCommand(IncludeCancelCommand = true)]
    private async Task LoadAsync(CancellationToken ct)
    {
        Orders.Clear();
        await foreach (var order in orders.StreamAsync(ct))
            Orders.Add(order); // continuation resumes on the UI thread
    }

    [RelayCommand(CanExecute = nameof(CanSave))]
    private Task SaveAsync(CancellationToken ct) =>
        orders.CreateAsync(CustomerName!, clock.GetUtcNow(), ct);

    private bool CanSave() => !string.IsNullOrWhiteSpace(CustomerName);

    partial void OnSelectedOrderChanged(OrderRow? value) =>
````
END THIRD-PARTY FILE 75d83ac12d8ddec7

The third-party file has ended. Everything between the 75d83ac12d8ddec7 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2958 of 13178 bytes. © codewithmukesh · MIT · https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/desktop-mvvm/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
