Back to Skills

using-wpf-behaviors-triggers

verified

Implements XAML behaviors and triggers using Microsoft.Xaml.Behaviors.Wpf. Use when adding interactivity to XAML without code-behind, implementing EventToCommand patterns, or creating reusable behaviors.

View on GitHub

Marketplace

dotnet-claude-plugins

christian289/dotnet-with-claudecode

Plugin

wpf-dev-pack

development

Repository

christian289/dotnet-with-claudecode
5stars

wpf-dev-pack/skills/using-wpf-behaviors-triggers/SKILL.md

Last Verified

January 23, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/christian289/dotnet-with-claudecode/blob/main/wpf-dev-pack/skills/using-wpf-behaviors-triggers/SKILL.md -a claude-code --skill using-wpf-behaviors-triggers

Installation paths:

Claude
.claude/skills/using-wpf-behaviors-triggers/
Powered by add-skill CLI

Instructions

# WPF Behaviors and Triggers

## 1. Setup

### 1.1 Install NuGet Package

```xml
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.*" />
```

### 1.2 XAML Namespace

```xml
<Window xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
```

---

## 2. EventTrigger

Executes actions when events occur.

### 2.1 InvokeCommandAction (MVVM Recommended)

```xml
<Button Content="Click Me">
    <b:Interaction.Triggers>
        <b:EventTrigger EventName="Click">
            <b:InvokeCommandAction Command="{Binding ClickCommand}"/>
        </b:EventTrigger>
    </b:Interaction.Triggers>
</Button>
```

### 2.2 With Event Args

```xml
<ListBox>
    <b:Interaction.Triggers>
        <b:EventTrigger EventName="SelectionChanged">
            <b:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
                                   PassEventArgsToCommand="True"/>
        </b:EventTrigger>
    </b:Interaction.Triggers>
</ListBox>
```

### 2.3 ChangePropertyAction

```xml
<Button Content="Toggle Visibility">
    <b:Interaction.Triggers>
        <b:EventTrigger EventName="Click">
            <b:ChangePropertyAction TargetName="MyPanel"
                                    PropertyName="Visibility"
                                    Value="Collapsed"/>
        </b:EventTrigger>
    </b:Interaction.Triggers>
</Button>

<StackPanel x:Name="MyPanel"/>
```

---

## 3. DataTrigger

Executes actions based on data conditions.

```xml
<TextBlock Text="{Binding Status}">
    <b:Interaction.Triggers>
        <b:DataTrigger Binding="{Binding IsLoading}" Value="True">
            <b:ChangePropertyAction PropertyName="Text" Value="Loading..."/>
            <b:ChangePropertyAction PropertyName="Foreground" Value="Gray"/>
        </b:DataTrigger>
        <b:DataTrigger Binding="{Binding HasError}" Value="True">
            <b:ChangePropertyAction PropertyName="Foreground" Value="Red"/>
        </b:DataTrigger>
    </b:Interaction.Triggers>
</TextBlock>
```

---

## 4. Cu

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6631 chars