defining-wpf-dependencypropertylisted
Install: claude install-skill christian289/dotnet-with-claudecode
# WPF DependencyProperty Patterns
Defining dependency properties for data binding, styling, animation, and property value inheritance.
**Advanced Patterns:** See [ADVANCED.md](ADVANCED.md) for value inheritance, metadata override, and event integration.
## 1. DependencyProperty Overview
```
Standard CLR Property:
private string _name;
public string Name { get => _name; set => _name = value; }
DependencyProperty:
public static readonly DependencyProperty NameProperty = ...
public string Name { get => (string)GetValue(NameProperty); set => SetValue(NameProperty, value); }
Benefits:
✅ Data Binding
✅ Styling & Templating
✅ Animation
✅ Property Value Inheritance
✅ Default Values
✅ Change Notifications
✅ Value Coercion
✅ Validation
```
---
## 2. Basic DependencyProperty
### 2.1 Standard Registration
```csharp
namespace MyApp.Controls;
using System.Windows;
using System.Windows.Controls;
public class MyControl : Control
{
// 1. Register DependencyProperty
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
name: nameof(Title),
propertyType: typeof(string),
ownerType: typeof(MyControl),
typeMetadata: new PropertyMetadata(defaultValue: string.Empty));
// 2. CLR property wrapper
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
}
```
### 2.2 With FrameworkPropertyMeta