# Devexpress Wpf Mvvm

> Build WPF applications with the DevExpress MVVM Framework — view-model strategies (compile-time GenerateViewModel source generator, runtime POCO ViewModelSource, ViewModelBase, BindableBase), DelegateCommand/AsyncCommand, predefined services (IMessageBoxService, IDialogService, IDocumentManagerService, INotificationService, INavigationService, IDispatcherService), behaviors (EventToCommand, KeyTo…

- **Type:** Skill
- **Install:** `agentstack add skill-devexpress-agent-skills-devexpress-wpf-mvvm`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [DevExpress](https://agentstack.voostack.com/s/devexpress)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [DevExpress](https://github.com/DevExpress)
- **Source:** https://github.com/DevExpress/agent-skills/tree/main/plugins/dx-wpf/skills/devexpress-wpf-mvvm
- **Website:** https://www.devexpress.com

## Install

```sh
agentstack add skill-devexpress-agent-skills-devexpress-wpf-mvvm
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# DevExpress WPF MVVM Framework

`DevExpress.Mvvm` is a full-featured MVVM framework for WPF — view-model base classes, code generators (compile-time and runtime), commands (sync and async), 25+ predefined services for typical UI tasks (message boxes, dialogs, document management, dispatcher, navigation, splash screens), behaviors that replace code-behind, and three view-model-communication mechanisms (parameter passing, parent-child relationships, messenger).

This skill covers picking the right view-model strategy, defining bindable properties and commands, calling services from view models, attaching behaviors, and routing data between view models.

## When to Use This Skill

Use this skill when you need to:

- Pick a view-model strategy for a new or existing project
- Generate boilerplate code (properties, INotifyPropertyChanged, commands) at compile time
- Wire commands (sync `DelegateCommand` or async `AsyncCommand`) to methods
- Show message boxes / dialogs / file pickers / notifications from a view model
- Replace code-behind event handlers with behaviors (`EventToCommand`, `KeyToCommand`, ...)
- Pass initial data to a child view model (`ISupportParameter`)
- Access services registered on the parent view's view model from a child (`ISupportParentViewModel`)
- Broadcast notifications across loosely coupled view models (`Messenger`)

## Prerequisites & Installation

### NuGet Packages

| Package | Provides |
|---------|---------|
| `DevExpress.Wpf.Core` | `ViewModelBase`, `BindableBase`, `Messenger`, all predefined services (`IMessageBoxService`, `IDialogService`, etc.), behaviors, `dxmvvm:` namespace |
| `DevExpress.Mvvm` | Standalone MVVM library (the same types) — use when not bringing the rest of DX WPF |
| `DevExpress.Mvvm.CodeGenerators` | Compile-time source generator for `[GenerateViewModel]` |

For a typical DevExpress WPF app, **install `DevExpress.Wpf.Core` only** — it brings everything. For a pure-MVVM library that doesn't reference UI controls, install `DevExpress.Mvvm` standalone.

For compile-time view-model generation, **also install** `DevExpress.Mvvm.CodeGenerators`:

```bash
dotnet add package DevExpress.Wpf.Core
dotnet add package DevExpress.Mvvm.CodeGenerators   # for compile-time view models
```

### Requirements per Strategy

|   | POCO View Models (runtime) | View Models generated at compile time |
|---|---|---|
| C# version | 6+ | 9+ |
| .NET Framework | 4.5.2+ | 4.6.1+ |
| .NET Core | 3.0+ | 3.0+ |
| VB support | Yes | No |
| Debug-step into generated code | No | Yes |

**For new projects, prefer the compile-time generator** — better tooling, debuggable, no runtime reflection cost. Use POCO only when targeting older runtimes or VB.NET. Use `ViewModelBase` when integrating with code that already uses it.

A valid DevExpress license is required. All DevExpress packages in a project must share the same version.

## XAML Namespaces

```xml
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
```

| Prefix | Use for |
|---|---|
| `dxmvvm:` | `Interaction.Behaviors`, `EventToCommand`, `KeyToCommand`, `ViewModelSource`, `ViewModelExtensions`, `MessageBoxService` (and most services) |
| `dx:` | Some services live here too (e.g., `DXMessageBoxService`) — match what's in the docs |

## View-Model Strategies — Picker

| Strategy | When to use |
|---|---|
| **`[GenerateViewModel]`** (compile-time, recommended) | New projects on C# 9+ / .NET 5+. Best tooling. |
| **`ViewModelSource.Create()`** (POCO, runtime-generated) | When you need VB support, or compile-time generator is unavailable |
| **`ViewModelBase`** (direct inheritance) | Existing codebases using it; when you need design-time helpers (`OnInitializeInDesignMode` / `OnInitializeInRuntime`) explicitly |
| **`BindableBase`** | Minimal — only `INotifyPropertyChanged` boilerplate. Use when not pulling in the full MVVM framework. |

> **Critical**: don't mix view-model strategies arbitrarily. If your project already uses one strategy across most view models, keep using it. Compile-time is the recommended default for new code.

Detailed comparison: [references/viewmodels.md](references/viewmodels.md).

## Before You Start — Ask the Developer

1. **Target framework**: .NET 8+, .NET 6/7, or .NET Framework 4.x? (Compile-time generation requires .NET Framework 4.6.1+ or .NET Core 3.0+.)
2. **Existing view-model style**: Does the project already use `ViewModelBase`, POCO, or compile-time generation? If yes, match it. If no, default to compile-time `[GenerateViewModel]`.
3. **Language**: C# only or also VB.NET? VB requires runtime POCO or `ViewModelBase` — compile-time gen is C#-only.
4. **Service usage**: Which services will be called from view models — message box / dialog / file picker / dispatcher? See [services.md](references/services.md).
5. **MVVM-style event handling**: Are there event handlers in code-behind that should become behaviors? See [behaviors.md](references/behaviors.md).
6. **View-model communication**: Do view models need to share data — parameter passing, parent reference, messenger? See [viewmodel-communication.md](references/viewmodel-communication.md).

## Documentation & Navigation Guide

### Getting Started
Refer to [references/getting-started.md](references/getting-started.md) (.NET 6/7/8+) or [references/getting-started-dotnet-fw.md](references/getting-started-dotnet-fw.md) (.NET Framework 4.x).

When you need to:
- Set up a new WPF project with the MVVM Framework
- Install the right NuGet packages
- Create the first view model and bind it to a view

### View Models — Strategies, Properties, Commands
Refer to [references/viewmodels.md](references/viewmodels.md)

When you need to:
- Pick between compile-time generator, runtime POCO, `ViewModelBase`, or `BindableBase`
- Define `INotifyPropertyChanged` properties in each style
- Wire `DelegateCommand` / `AsyncCommand` to methods in each style
- Migrate between styles

### Services
Refer to [references/services.md](references/services.md)

When you need to:
- Show a message box, dialog, file picker, notification from a view model
- Register a service in XAML and call it from C#
- Use one of the 25+ predefined services
- Create a custom service

### Behaviors
Refer to [references/behaviors.md](references/behaviors.md)

When you need to:
- Attach `EventToCommand` to route an event to a view-model command
- Use `KeyToCommand` for keyboard shortcuts
- Use `FocusBehavior`, `ConfirmationBehavior`, `EnumItemsSourceBehavior`, etc.
- Write a custom `Behavior` class

### View-Model Communication
Refer to [references/viewmodel-communication.md](references/viewmodel-communication.md)

When you need to:
- Pass initialization data to a child view model (`ISupportParameter`)
- Give a child view model access to its parent (`ISupportParentViewModel`)
- Broadcast a notification across loosely coupled view models (`Messenger`)
- Pick the right communication mechanism

## Quick Start — Compile-Time View Model

```csharp
using DevExpress.Mvvm.CodeGenerators;

[GenerateViewModel]
partial class MainViewModel {
    [GenerateProperty]
    string username = "";

    [GenerateProperty]
    string status = "";

    [GenerateCommand]
    void Login() => Status = $"User: {Username}";
    bool CanLogin() => !string.IsNullOrEmpty(Username);
}
```

The generator produces a partial class with the property + INPC + command boilerplate — no manual `RaisePropertyChanged` calls, no `new DelegateCommand(...)` wiring.

```xaml

    
        
    
    
        
        
        
    

```

## Quick Start — ViewModelBase (Traditional)

```csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;

public class MainViewModel : ViewModelBase {
    public string Username {
        get => GetProperty(() => Username);
        set => SetProperty(() => Username, value);
    }

    [Command]
    public void Login() { /* ... */ }
    public bool CanLogin() => !string.IsNullOrEmpty(Username);
}
```

The `[Command]` attribute auto-generates a `LoginCommand` property at runtime (via `ICustomTypeDescriptor`); `Can[MethodName]` is auto-discovered.

## Quick Start — Runtime POCO

```csharp
public class MainViewModel {
    public virtual string Username { get; set; } = "";

    public void Login() { /* ... */ }
    public bool CanLogin() => !string.IsNullOrEmpty(Username);

    protected MainViewModel() { }
    public static MainViewModel Create() => DevExpress.Mvvm.POCO.ViewModelSource.Create(() => new MainViewModel());
}
```

```xaml

```

The runtime generator wraps the class in a descendant that adds `INotifyPropertyChanged` to virtual properties and creates `LoginCommand` from the `Login` method.

## Key API Surface

### Commands

| Class | Use |
|---|---|
| `DelegateCommand` | Sync command (no parameter) |
| `DelegateCommand` | Sync command with a typed parameter |
| `AsyncCommand` | Async command (no parameter) — returns `Task` |
| `AsyncCommand` | Async command with a typed parameter |

```csharp
public ICommand SaveCommand => new DelegateCommand(Save, CanSave);
public ICommand LoadCommand => new AsyncCommand(LoadAsync);
```

In compile-time generation: `[GenerateCommand]` on a method auto-creates the command property (sync if the method returns `void`, async if it returns `Task`).

### `ViewModelBase` Members

| Member | Use |
|---|---|
| `GetProperty(() => Prop)` / `SetProperty(() => Prop, value)` | Bindable property pattern (expression-based) |
| `GetService()` | Resolve a service registered on the view |
| `OnInitializeInRuntime()` / `OnInitializeInDesignMode()` | Different initialization for design vs runtime |
| `OnParameterChanged(object)` | Receive data passed via `ISupportParameter` |
| `OnParentViewModelChanged(object)` | Receive parent VM reference |
| `IsInDesignMode` | Detect designer mode |

### Compile-Time Attributes (`DevExpress.Mvvm.CodeGenerators`)

| Attribute | Use |
|---|---|
| `[GenerateViewModel]` (on class) | Tells the source generator to emit boilerplate |
| `[GenerateProperty]` (on field) | Emit a public property + INPC raise |
| `[GenerateCommand]` (on method) | Emit a Command property |

`GenerateViewModel` properties: `ImplementINotifyPropertyChanging`, `ImplementIDataErrorInfo`, `ImplementISupportServices`, `ImplementISupportParentViewModel`.

### Predefined Services (Selected)

| Service | Use |
|---|---|
| `IMessageBoxService` (`DXMessageBoxService` / `WinUIMessageBoxService`) | Show message boxes |
| `IDialogService` (`DialogService` / `WinUIDialogService`) | Show modal dialogs with a view |
| `IDocumentManagerService` (`WindowedDocumentUIService`, `TabbedDocumentUIService`, ...) | Manage tabbed / windowed / docked documents |
| `IOpenFileDialogService` / `ISaveFileDialogService` / `IFolderBrowserDialogService` | Standard file/folder pickers |
| `INotificationService` | Toast-style notifications |
| `INavigationService` | Navigate between views inside a `NavigationFrame` |
| `IDispatcherService` | Marshal work onto the UI dispatcher |
| `ISplashScreenManagerService` | Show a splash screen from a VM |
| `ICurrentWindowService` / `ICurrentDialogService` | Control the hosting window from a VM |
| `IWindowService` | Show a view as a separate window |

Full list: [services.md](references/services.md).

## Common Patterns

### Pattern 1: Compile-Time VM with Services

```csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.CodeGenerators;

[GenerateViewModel(ImplementISupportServices = true)]
partial class MainViewModel {
    IMessageBoxService MessageBox =>
        ServiceContainer.GetService(ServiceSearchMode.PreferParents);

    [GenerateCommand]
    void ShowAbout() => MessageBox.ShowMessage("MyApp v1.0");
}
```

```xaml

    
        
    
    ...

```

### Pattern 2: Async Command with Progress

```csharp
[GenerateViewModel]
partial class MainViewModel {
    [GenerateProperty]
    bool isBusy;

    [GenerateCommand]
    async Task LoadAsync() {
        IsBusy = true;
        try { await FetchDataAsync(); }
        finally { IsBusy = false; }
    }
}
```

`AsyncCommand` is auto-detected when the method returns `Task`. Use `AllowMultipleExecution = true` on `[GenerateCommand]` to allow re-entry.

### Pattern 3: Behavior — Event to Command

```xaml

    
        
    

```

No code-behind needed; double-click routes to `EditCommand` on the view model.

### Pattern 4: Pass Data to Child VM

```xaml

    
        
    

```

The detail view-model's `OnParameterChanged(object)` is invoked with the new value.

### Pattern 5: Messenger Broadcast

```csharp
// Sender
Messenger.Default.Send("ItemAdded");

// Receiver (subscribe in ctor)
Messenger.Default.Register(this, OnMessage);
void OnMessage(string msg) { /* react */ }
```

Loosely coupled — sender and receiver don't know about each other.

## Troubleshooting

| Symptom | Cause | Solution |
|---|---|---|
| `[GenerateViewModel]` doesn't emit any code | `DevExpress.Mvvm.CodeGenerators` package missing, or C# 9` (or higher) in `.csproj`. |
| Compile-time generated code can't be found | Generated files aren't visible in plain code search | Use **Peek Definition** (F12) on a generated member, or look under `Dependencies → Analyzers → DevExpress.Mvvm.CodeGenerators` in Solution Explorer. |
| `ViewModelSource.Create` throws "type must be public and not sealed" | POCO classes need `public` non-sealed classes with virtual properties | Make the class `public` and properties `virtual`. |
| `Command` attribute method doesn't become a command | Class doesn't inherit from `ViewModelBase`, or method is private | Inherit from `ViewModelBase` and make the method `public`. |
| `GetService()` returns `null` | Service not registered on the view via `` | Add the service to the view's behaviors collection. |
| `Messenger.Default.Register` listener never fires | Recipient was garbage-collected (Messenger uses weak refs by default), or message types don't match | Keep a reference to the recipient; verify `TMessage` types are exactly the same. |
| `OnParameterChanged` not invoked | `ViewModelExtensions.Parameter` attached property assigned with wrong binding (DataContext == DetailVM, but should reference Main VM) | Use `{Binding DataContext, ElementName=LayoutRoot}` not `{Binding}`. |
| Behavior doesn't attach | Missing `dxmvvm:` namespace, or behavior not in `` collection | Add namespace `xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"` and wrap behaviors in the collection. |

## Constraints & Rules

CRITICAL — follow these rules in every interaction:

1. **Build verification**: After changes, run `dotnet build` and report errors before claiming success.
2. **Target framework**: Windows-only (`net{X}-windows`, `UseWPF=true`).
3. **NuGet**: `DevExpress.Wpf.Core` (or `DevExpress.Mvvm` for the standalone library). Add `DevExpress.Mvvm.CodeGenerators` for compile-time generation.
4. **For new projects, prefer compile-time `[GenerateViewModel]`**. Use POCO/`ViewModelBase` only when constrained (VB, older runtime, existing codebase).
5. **Don't mix view-model strategies within a project** unless there's a deliberate reason — pick one and stick with it.
6. **XAML namespaces**: `dxmvvm:` (MVVM framework primitives). Some services use `dx:` — check the docs per service.
7. **POCO requires `virtual`** on properties and a `public` non-sealed class. Don't try `ViewModelSource.Create` on sealed classes.
8. **`Messenger.Default` uses weak references** — keep recipients alive (typically members on a long-lived view model) or messages won't fire.

## Using DevExpress Documentation MCP

- **Search**: `devexpress_docs_search(technology="WPF", query="MVVM view model service behavior")`
- **Fetch**: `devexpress_docs_get_content(url="https://docs.devexpress.com/WPF/17414")`

Use MCP for: specific service APIs (each predefined service has its own configuration), advanced compile-time generation scenarios (Prism, MVVM Light), Dependency Injection patterns, custom servi

…

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [DevExpress](https://github.com/DevExpress)
- **Source:** [DevExpress/agent-skills](https://github.com/DevExpress/agent-skills)
- **License:** MIT
- **Homepage:** https://www.devexpress.com

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-devexpress-agent-skills-devexpress-wpf-mvvm
- Seller: https://agentstack.voostack.com/s/devexpress
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
