What's the difference between a dependency property and an attached property in WPF?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In WPF, an attached property is not a completely separate property system from a dependency property. It is a special kind of dependency property that is registered so one type can set a value on other objects. The practical difference is about ownership and intended usage, not about whether the value participates in the WPF property system.
Dependency Properties Are WPF-Native Properties
A dependency property is a property registered with WPF so it can participate in features such as:
- data binding
- styling
- animation
- default values
- property value inheritance
- change callbacks
A normal CLR property does not automatically get those WPF capabilities.
Example of a custom dependency property:
This property belongs to HighlightBox. That is the normal dependency-property pattern.
Attached Properties Are Meant to Be Set on Other Objects
An attached property is registered differently because its purpose is usually to let one class store or interpret property values on another class.
The classic example is Grid.Row:
The Button does not own a Row CLR property. The Grid class defines an attached property that child elements can carry so the parent grid knows how to lay them out.
How Attached Properties Are Declared
Attached properties use RegisterAttached and static getter and setter methods.
Usage in XAML:
The button stores the value, but the defining class is LayoutHints.
Both Still Use the Same WPF Property Engine
This is the most important conceptual point: attached properties are still dependency properties under the hood. They support the same WPF property-system features, because they are registered into that same system.
So the wrong mental model is:
- dependency property versus attached property as unrelated things
The better model is:
- normal dependency property: owned and typically used directly by the declaring type
- attached property: registered so other objects can carry the value too
When to Use a Normal Dependency Property
Use a normal dependency property when the property is part of the object's own API.
Examples:
- '
Button.IsDefault' - '
TextBox.Text' - a custom control's
IsHighlighted
In these cases, the object conceptually owns the property, and the property is naturally accessed as part of that object's behavior.
When to Use an Attached Property
Use an attached property when another object, often a parent, service, or behavior system, needs metadata on a target object.
Typical examples:
- layout metadata such as
Grid.Row - behavior flags used by helper classes
- cross-cutting UI hints applied to arbitrary controls
The attached form is useful precisely because the target object does not need to define the property in its own class.
Many Attached Properties Are Also Service-Like
Some attached properties are not only for layout. They let helper classes attach extra behavior or state to arbitrary elements.
That means an attached property can act like a small extension point for the visual tree without subclassing every control involved.
The XAML Syntax Makes the Difference Visible
XAML shows the distinction very clearly.
Normal dependency property:
Attached property:
Text belongs to TextBox. Grid.Row belongs to Grid but is attached to the TextBox instance.
Common Pitfalls
- Thinking attached properties are separate from dependency properties rather than a specialized form of them.
- Using an attached property when the property really belongs to the control's own API.
- Forgetting the required static
GetandSetmethods for custom attached properties. - Assuming attached properties are only for layout when they can also support behaviors and services.
- Overusing attached properties for ordinary object design problems that would be clearer with normal properties.
Summary
- A dependency property is a WPF property registered with the dependency-property system.
- An attached property is a dependency property intended to be set on other objects.
- Normal dependency properties belong to the owning control's API.
- Attached properties are commonly used for layout and cross-cutting UI metadata.
- The real distinction is ownership and usage pattern, not a separate runtime mechanism.

