wpf 我什么时候应该在普通的 PropertyMetadata 上使用 FrameworkPropertyMetadata 或 UIPropertyMetadata?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2486999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:36:02  来源:igfitidea点击:

When should I use FrameworkPropertyMetadata or UIPropertyMetadata over plain PropertyMetadata?

wpfattached-propertiesattachedbehaviors

提问by Roger Lipscombe

When looking at sample attached properties and behaviors, I've seen a mishmash of uses of FrameworkPropertyMetadata, UIPropertyMetadataand PropertyMetadata. Since they all form an inheritance hierarchy, how do I choose which one to use?

在查看示例附加属性和行为时,我看到了FrameworkPropertyMetadata,UIPropertyMetadata和的混合使用PropertyMetadata。既然都形成了一个继承层次,那我该如何选择使用哪一个呢?

采纳答案by gp.

These classes are to report some behavior aspects of a dependency property.

这些类将报告依赖属性的一些行为方面。

Check the different classes for the options they provide.

检查不同的类以了解它们提供的选项。

For example,

例如,

if you just want to back a property by dp and provide a default value, use PropertyMetadata,

如果您只想通过 dp 支持属性并提供默认值,请使用PropertyMetadata,

if you want to specify animation behavior, use UIPropertyMetadata,

如果要指定动画行为,请使用UIPropertyMetadata,

but if some property affects wpf framework level stuffs eg element layout, parent layout or databinding, use FrameworkPropertyMetadata.

但是如果某些属性影响 wpf 框架级别的东西,例如元素布局、父布局或数据绑定,请使用FrameworkPropertyMetadata.

Details you can check on msdn http://msdn.microsoft.com/en-us/library/ms751554.aspx

您可以在 msdn http://msdn.microsoft.com/en-us/library/ms751554.aspx上查看详细信息