views:

1113

answers:

1

What's the difference between a (custom) dependency property and an attached property in WPF? What are the uses for each? How do the implementations typically differ?

+5  A: 

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.

Reed Copsey