What’s the difference between a dependency property and an attached property in WPF?

Attached properties are a type of dependency property. The difference is in how they’re used.

With an attached property, the property is defined on a class that isn’t the same class for which it’s being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row – you apply this to a control (ie: Button), but it’s actually defined in Panel or Grid. The property is “attached” to the button’s instance.

This allows a container, for example, to create properties that can be used on any UIelement.

As for implementation differences – it’s basically just a matter of using Register vs. RegisterAttached when you define the property.

Leave a Comment