Please visit DEMANDDRAFT.STORE for quality of products...

Ad

Search This Blog

Saturday, July 21, 2012

What are attached properties in WPF

What are attached properties?
Attached properties allow child elements to define values for a parent element’s properties.  They only make sense in the context of a hierarchical element tree.

Some implementation details
An attached property defined in XAML as <Button x:Name=”myButton” DockPanel.Dock=”Top”/> is written in code as DockPanel.Dock(myButton, Dock.Top).

So Dock is defined as a static function that sets the appropriate position properties for the button for it to be docked.

But how does this static function then know which DockPanel to dock button to?  It simply traverses up the element tree from myButton until it finds a DockPanel.

No comments:

Post a Comment