用错误的名称注册附加属性 [英] Register attached property with wrong name

查看:94
本文介绍了用错误的名称注册附加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自System.Windows.Interactivity.dll:

From System.Windows.Interactivity.dll:

private static readonly DependencyProperty BehaviorsProperty = DependencyProperty.RegisterAttached("ShadowBehaviors", typeof(BehaviorCollection), typeof(Interaction), new FrameworkPropertyMetadata(new PropertyChangedCallback(Interaction.OnBehaviorsChanged)));

public static BehaviorCollection GetBehaviors(DependencyObject obj)
{
  BehaviorCollection behaviors = (BehaviorCollection) obj.GetValue(BehaviorsProperty);
  if (behaviors == null)
  {
    behaviors = new BehaviorCollection();
    obj.SetValue(BehaviorsProperty, behaviors);
  }
  return behaviors;
}



由于依赖项属性被命名为 ShadowBehaviors ,因此该行为不符合约定.您能解释一下为什么这似乎是Microsoft故意的.



This behavior doesn''t follow the convention since the dependency property is named ShadowBehaviors. Can you explain why, it seems deliberate by Microsoft.

推荐答案

我认为他们这样做是因为依赖项属性是私有属性,因此他们不需要遵守约定.

另外还要明确说明此属性仅供内部使用.

您是否阅读了BehaviorsProperty的评论?

因为我只有德语版本,所以这里有一个粗略的翻译:

总结:
此属性用作附加到公共行为的属性的内部备份存储."

备注:
``此属性不是公开可用的.这迫使客户端使用GetBehaviors和SetBehaviors方法来访问该集合,以确保在使用该集合之前对其进行了初始化.''
问候,



托马斯.
I think they did it because the dependency property is a private one and so they don''t need to follow the conventions.

Also to make clear that this property is intended only for internal use.

Did you read the comment of the BehaviorsProperty?

As I only have the german version, here a rough translation:

in summary:
''This property is used as internal backup storage for the property that is attached to the public behaviors.''

in remarks:
''This property is not publicly available. This forces clients to use the methods GetBehaviors and SetBehaviors to access the collection to make sure that the collection is initialized before being used.''

Regards,



Thomas.


这篇关于用错误的名称注册附加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆