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 GitHubchristian289/dotnet-with-claudecode
wpf-dev-pack
January 23, 2026
Select agents to install to:
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-triggersInstallation paths:
.claude/skills/using-wpf-behaviors-triggers/# 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