Back to Skills

routing-wpf-events

verified

Implements WPF routed events including Bubbling, Tunneling, and Direct strategies. Use when creating custom routed events, handling event propagation, or understanding Preview events.

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/routing-wpf-events/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/routing-wpf-events/SKILL.md -a claude-code --skill routing-wpf-events

Installation paths:

Claude
.claude/skills/routing-wpf-events/
Powered by add-skill CLI

Instructions

# WPF Routed Events Patterns

Understanding and implementing WPF's routed event system for event propagation through element trees.

## 1. Routing Strategies Overview

```
                    Window (Root)
                       │
    ┌──────────────────┼──────────────────┐
    │                  │                  │
  Grid              Border            StackPanel
    │                  │                  │
 Button             TextBox           ListBox
    │
ContentPresenter
    │
 TextBlock (Event Source)

Tunneling (Preview): Window → Grid → Button → ContentPresenter → TextBlock
Bubbling:            TextBlock → ContentPresenter → Button → Grid → Window
Direct:              Only TextBlock
```

---

## 2. Routing Strategy Types

| Strategy | Direction | Event Name Pattern | Use Case |
|----------|-----------|-------------------|----------|
| **Tunneling** | Root → Source (downward) | PreviewXxx | Input validation, cancellation before processing |
| **Bubbling** | Source → Root (upward) | Xxx | Normal event handling |
| **Direct** | Source only | Xxx | Events that don't propagate (MouseEnter, MouseLeave) |

---

## 3. Tunneling and Bubbling Example

### 3.1 XAML Setup

```xml
<Window PreviewMouseDown="Window_PreviewMouseDown"
        MouseDown="Window_MouseDown">
    <Grid PreviewMouseDown="Grid_PreviewMouseDown"
          MouseDown="Grid_MouseDown">
        <Button PreviewMouseDown="Button_PreviewMouseDown"
                MouseDown="Button_MouseDown"
                Content="Click Me"/>
    </Grid>
</Window>
```

### 3.2 Event Handler Order

```csharp
// Execution order when Button is clicked:
// 1. Window_PreviewMouseDown  (Tunneling)
// 2. Grid_PreviewMouseDown    (Tunneling)
// 3. Button_PreviewMouseDown  (Tunneling)
// 4. Button_MouseDown         (Bubbling)
// 5. Grid_MouseDown           (Bubbling)
// 6. Window_MouseDown         (Bubbling)

private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
    Debug.WriteLine("1. Window PreviewMouse

Validation Details

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