Difference between Attached and non-Attached Dependency Properties in Silverlight

后端 未结 5 1312
心在旅途
心在旅途 2020-12-17 17:09

Okay Stackers, I\'ve spent a good couple of hours on this question, and I want to know if anybody has a definitive answer.
For all the research I\'ve done, I can\'t fin

5条回答
  •  Happy的楠姐
    2020-12-17 17:36

    Given the discussions flowing in comments I will try to do this one in plain English:

    The main difference between Attached Dependency Properties and Dependency Properties (and therefore between .Register and .RegisterAttached) is that RegisterAttached allows the value to be assigned to any dependency object whereas Register only allows it to be attached to the class passed as the ownerType parameter.

    As Haris Hasan mentions (deep in the comment thread), your example is using the only type allowed (i.e. CustomControl) and does not show you that the Attached version can be assigned to ANY dependency object.

    e.g. you can do this with your Attached Dependency Property (but not a plain DP):

    
    
    

    The best reference for ADPs I can find is this one: http://msdn.microsoft.com/en-us/library/ms749011.aspx

    We used ADPs as the basis of a localisation system, so that translations could be parasited onto objects during load rather than using horrendously long bindings. Couldn't do that with DPs

    Update:

    I would also like to clarify that the parent limitation applies to XAML based use of the attribute. From code the parent limitation apparently does not apply.

提交回复
热议问题