defining-wpf-dependencyproperty

Defines WPF DependencyProperty registrations with metadata, callbacks, validation, and attached properties.

Updated Nov 22, 2023
One-click install
npx skills add https://github.com/parksanghoon-sys/TestCode --skill defining-wpf-dependencyproperty-parksanghoon-sys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: defining-wpf-dependencyproperty
Source: https://github.com/parksanghoon-sys/TestCode/tree/main/src/Modbus/wpf-dev-pack/.agents/skills/defining-wpf-dependencyproperty
Command: npx skills add https://github.com/parksanghoon-sys/TestCode --skill defining-wpf-dependencyproperty-parksanghoon-sys

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Creating bindable, styleable properties on WPF custom controls requires verbose DependencyProperty registration boilerplate with correct metadata flags, callbacks, and validation, which is error-prone when written from memory. ## Core Features & Use Cases - Standard Registration: Generate DependencyProperty declarations with CLR wrappers, default values, and FrameworkPropertyMetadata flags like AffectsRender and BindsTwoWayByDefault. - Callbacks & Validation: Implement PropertyChangedCallback, CoerceValueCallback, and ValidateValueCallback in the correct execution order. - Attached & Read-Only Properties: Create attached properties with Get/Set accessors and read-only properties using DependencyPropertyKey. - Use Case: When building a custom ProgressControl, use this Skill to register a Progress property that coerces values into the 0-100 range and triggers re-rendering on change. ## Quick Start Ask the AI to define a WPF DependencyProperty with a change callback and value coercion for your custom control.

Frequently Asked Questions about defining-wpf-dependencyproperty

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a DependencyProperty in a WPF custom control?▼

Register a static readonly DependencyProperty using DependencyProperty.Register with the property name, type, owner type, and PropertyMetadata, then expose it through a CLR wrapper that calls GetValue and SetValue. This enables data binding, styling, and animation support.

How to add PropertyChangedCallback and CoerceValueCallback to a WPF DependencyProperty?▼

Pass both callbacks through FrameworkPropertyMetadata when registering the property. Validation runs first via ValidateValueCallback, then CoerceValueCallback can modify the value, and finally PropertyChangedCallback handles the applied change.

What is the difference between DependencyProperty and attached property in WPF?▼

A DependencyProperty is registered on the owning control type with a CLR wrapper, while an attached property is registered via RegisterAttached on a static class with static Get and Set methods. Attached properties can be set on any DependencyObject in XAML.

Why is my DependencyProperty default value not being applied?▼

The default value must be set through PropertyMetadata during registration, not by assigning the CLR wrapper in the constructor. Setting the wrapper creates a local value that overrides the metadata default and can break style triggers.

When should I use DependencyProperty instead of INotifyPropertyChanged?▼

Use DependencyProperty on visual elements like custom controls where you need styling, animation, and property value inheritance. Use INotifyPropertyChanged in ViewModels and plain data classes that are not DependencyObjects.