Link to home
Start Free TrialLog in
Avatar of milani_lucie
milani_lucieFlag for United States of America

asked on

Dependency Property vs Attached Property - WPF

Hi,

I have the following statement:

Attached properties differ from normal dependency properties in that they are not wrapped in CLR properties (i.e. standard .NET properties).

Dependency Properties Example:

<Canvas>
                   <Rectangle Height="72" Width="131" Canvas.Left="74" Canvas.Top="77" />
</Canvas>

Attached Properties Example:

<DockPanel>
      <Button x:Name="Button1" DockPanel.Dock="Left" />
</DockPanel>

Can you please let me know what is the difference between these two ? It looks like both are same but i am missing something !

Thanks
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

The basic difference is that Attached Properties are dependency properties defined in a parent control and attached to a child control.  In your sample Canvas.Left is a property of Canvas, but it's attached to Rectangle.

More here:

Dependency Properties Overview
http://msdn.microsoft.com/en-us/library/ms752914.aspx

Attached Properties Overview
http://msdn.microsoft.com/en-us/library/ms749011.aspx
Avatar of milani_lucie

ASKER

wdosanjos:

Can you please define in simple terms:

What are Attched Properties ? What are Dependency Properties ? As per your definition, Attached Properties are nothing but Dependency Properties but attached to child controls. Am i correct ?

Can be Dependency Properties exist without attaching to child controls ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial