Skip to content
Skills Library
Programming · Building & coding

make-wpf-behavior

/make-wpf-behavior

Generates WPF Behavior<T> classes using Microsoft.Xaml.Behaviors.Wpf. Use when adding reusable interaction logic to controls, creating drag behaviors, or scaffolding a new Behavior class. Usage: /wpf-dev-pack:make-wpf-behavior <BehaviorName>

Licence
MIT
Last repository change
21.07.2026

Assessment and security

84/ 100Class: good
Format9 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 21.07.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Generates WPF Behavior<T> classes using Microsoft.Xaml.Behaviors.Wpf. Use when adding reusable interaction logic to controls, creating drag behaviors, or scaffolding a new Behavior class. Usage: /wpf-dev-pack:make-wpf-behavior <BehaviorName>

Arguments

/make-wpf-behavior [BehaviorName]
Original author description

Generates WPF Behavior<T> classes using Microsoft.Xaml.Behaviors.Wpf. Use when adding reusable interaction logic to controls, creating drag behaviors, or scaffolding a new Behavior class. Usage: /wpf-dev-pack:make-wpf-behavior <BehaviorName>

How it works

  1. Generated Code
  2. XAML Usage
  3. Common Behavior Patterns
  4. Required Package
  5. File Location
  6. Best Practices
  7. Related
Original SKILL.md headings · 166 lines, 416 words
SKILL.md preview
---
description: "Generates WPF Behavior<T> classes using Microsoft.Xaml.Behaviors.Wpf. Use when adding reusable interaction logic to controls, creating drag behaviors, or scaffolding a new Behavior class. Usage: /wpf-dev-pack:make-wpf-behavior <BehaviorName>"
argument-hint: [BehaviorName]
---

# WPF Behavior Generator

**If `$0` is empty, use the AskUserQuestion tool to ask: "Enter the Behavior name (e.g., SelectAllOnFocus, DragMove)". Do NOT proceed until a valid name is provided. Use the response as the BehaviorName for all subsequent steps.**

Generate a `$0Behavior` class based on Microsoft.Xaml.Behaviors.Wpf.

- Replace `{TargetType}` with the appropriate WPF type (e.g., TextBox, UIElement, Window) based on the behavior name and context.
- Replace `{Namespace}` with the project's root namespace detected from csproj or existing code.
- Replace `{Project}` with the target project path.

## Generated Code

```csharp
namespace {Namespace}.Behaviors;

public sealed class $0Behavior : Behavior<{TargetType}>
{
    #region Dependency Properties

    public static readonly DependencyProperty IsEnabledProperty =
        DependencyProperty.Register(
            nameof(IsEnabled),
            typeof(bool),
            typeof($0Behavior),
            new PropertyMetadata(true));

    public bool IsEnabled
    {
        get => (bool)GetValue(IsEnabledProperty);
        set => SetValue(IsEnabledProperty, value);
    }

    #endregion

    #region Lifecycle

    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.Loaded += OnLoaded;
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.Loaded -= OnLoaded;
    }

    #endregion

    #region Event Handlers

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        if (!IsEnabled)
        {
            return;
        }

        // TODO: Implement behavior logic
    }

    #endregion
}
```

## XAML Usage

```xml
<Window xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:behaviors="clr-namespace:{Namespace}.Behaviors">

    <{TargetType}>
        <b:Interaction.Behaviors>
            <behaviors:$0Behavior IsEnabled="{Binding IsBehaviorEnabled}"/>
        </b:Interaction.Behaviors>
    </{TargetType}>

</Window>
```

## Common Behavior Patterns

### Focus Management

```csharp
public sealed class FocusOnLoadBehavior : Behavior<UIElement>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.Loaded += (s, e) => AssociatedObject.Focus();
    }
}
```

### Input Handling

```csharp
public sealed class EnterKeyBehavior : Behavior<TextBox>
{
    public static readonly DependencyProperty CommandProperty =
        DependencyProperty.Register(nameof(Command), typeof(ICommand),
            typeof(EnterKeyBehavior));

    public ICommand? Command
    {
        get => (ICommand?)GetValue(CommandProperty);
        set => SetValue(CommandProperty, value);
    }

    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.KeyDown += OnKeyDown;
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.KeyDown -= OnKeyDown;
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            Command?.Execute(AssociatedObject.Text);
        }
    }
}
```

## Required Package

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

## File Location

```
{Project}/
└── Behaviors/
    └── $0Behavior.cs
```

## Best Practices

| DO | DON'T |
|----|-------|
| Unsubscribe events in OnDetaching | Missing event unsubscription (memory leak) |
| Expose settings via DependencyProperty | Use hardcoded values |
| Apply IsEnabled pattern | Always execute without condition |
| Check AssociatedObject for null | Use without null check |

## Related

- `/wpf-dev-pack:make-wpf-chatclient` emits two worked `Behavior<T>` instances
  built on this template: an `EnterCommandBehavior` (Enter=send / Shift+Enter=newline,
  IME-safe, via `PreviewKeyDown` with a `Command`/`CommandParameter` DP pair) and a
  `StickToBottomBehavior` (pin a streaming `ScrollViewer` to the newest content unless
  the user scrolled up). See it for a Command-DP behavior and an event-tracking behavior
  in context.

Versions

The database has no other skills named make-wpf-behavior.

Database snapshot: 13.11.2026 · package version 27788c03e9e3 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 84using-wpf-behaviors-triggers
    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.
  • 84make-wpf-converter
    Generates WPF IValueConverter or IMultiValueConverter classes with MarkupExtension pattern. Use when creating a new value converter, scaffolding a MultiValueConverter, or adding a converter with direct XAML usage. Usage: /wpf-dev-pack:make-wpf-converter <ConverterName> [multi]
  • 96dotnet-wpf
    .NET WPF component and application patterns Triggers on: **/*.xaml, **/*.cs
  • 86wpf
    WPF桌面应用开发专家助手。当用户需要进行Windows桌面应用开发、XAML界面设计、MVVM架构或WPF数据绑定时调用。
  • 95desktop-wpf
    Use when the user asks about WPF (.NET Framework or .NET Core/5+/6+), XAML desktop apps, MVVM with WPF, XAML data binding, or WPF custom controls. Do NOT use for: WinForms (desktop-winforms), WinUI 3 (desktop-winui3), or UWP (desktop-uwp).
  • 100wpf
    ATC WPF controls library (160+ controls, forms, components, theming) and cross-platform XAML toolkit (MVVM, source generators, behaviors). Use when the user asks to build a WPF desktop application, add WPF controls or forms, implement MVVM with source generators, use…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.