How can I most easily determine whether a property is a dependency property?

蓝咒 提交于 2019-12-12 12:35:49

问题


I recently had an issue with databinding to the Visibility property of a DataGridTextColumn. The confusion arose because this property is a dependecy property in WPF but not in Silverlight.

I don't think that the MSDN documentation makes this very clear. The following is the only related text for WPF.

"For information about what can influence the value, see DependencyProperty."

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.visibility(v=VS.100).aspx


回答1:


Dependency properties have a corresponding static field on the class they are defined in. Have a look at the fields section of the DataGridTextColumn class.




回答2:


In most cases you can detect whether a property Foo is a DP by checking if there is a static field named FooProperty of type DependencyProperty. However, this is only a convention. There is no guarantee that all dependency properties will follow this pattern.




回答3:


Already answered, I know. IE. The "Text" property in a "TextBlock" is a dependency property you can tell because Intellisense shows the static filed like this:

TextBlock.TextProperty



来源:https://stackoverflow.com/questions/6858995/how-can-i-most-easily-determine-whether-a-property-is-a-dependency-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!