属性值继承 [英] Property Value Inheritance

查看:30
本文介绍了属性值继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MSDN 和其他资源上进行大量搜索后,我基本上发现某些"依赖属性确实支持类似于 WPF 的属性值继承.但是,据我所知,没有明确的列表可以说明哪些属性可以,哪些不可以.我知道字体属性,例如,做;然而 Horizo​​ntalContentAlignment 没有.我还看到了这个论坛中的另一个线程,它指出 DP 优先级列表不包括值继承(http://msdn.microsoft.com/en-us/library/cc265148(VS.95).aspx#listing).

After much searching on MSDN and other sources I have basically found that "some" Dependancy Properties do indeed support property value inheritance similar to WPF. However, as far as I can tell, there is no definitive list of which properties do, and which do not. I know Font properties, for example, do; yet HorizontalContentAlignment does not. I have also seen the other thread in this forum which points out that the DP Precedence list does not include value inheritance (http://msdn.microsoft.com/en-us/library/cc265148(VS.95).aspx#listing).

此外,似乎甚至不可能将 Inheritable 元数据应用于任何自定义 DP,因此 Silverlight 框架似乎已针对特定属性对其进行了自定义.我需要确切地知道哪些依赖属性确实支持属性值继承.如果我错过了关于此的明显文章或主题,那么我很抱歉,但我的搜索非常彻底.

Furthermore, it seems that it is not possible to even apply Inheritable metadata to any custom DP, so it seems the silverlight framework has custom hacked it in for specific properties. I need to know exactly which dependancy properties do indeed support property value inheritance. If I have missed an obvious article on this, or a thread, then I apologize but I have been pretty thorough in my search.

谢谢.

推荐答案

你提到字体属性支持这个,所以我在反射器中做了一些挖掘,发现这很有趣:

You mention that the Font properties support this so I did a little digging in reflector and found this interesting:

文本块

public static readonly DependencyProperty FontSizeProperty = DependencyProperty.RegisterCoreProperty(0x40003714, typeof(double));

控制

public static readonly DependencyProperty FontSizeProperty = DependencyProperty.RegisterCoreProperty(0x80003714, typeof(double));

内联

public static readonly DependencyProperty FontSizeProperty = DependencyProperty.RegisterCoreProperty(0x3714, typeof(double));

所以这三个类都定义了一个 FontSizeProperty 并且使用的 id 看起来非常相似,就好像第一位只是某种标志.因此,也许在幕后进行的某些事情允许您所谓的属性继承,因为框架可能会在这些相似的 dp id 之间传输值.

So all three of those classes define a FontSizeProperty and the id used look very similar as if that first bit is just a flag of some kind. So perhaps there is something going on under the covers that allows what you're calling property inheritance since the the framework might transfer the values between these similar dp ids.

这篇关于属性值继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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