我最近遇到了将数据绑定到 DataGridTextColumn 的 Visibility 属性的问题。造成混乱的原因是此属性在 WPF 中是依赖属性,但在 Silverlight 中不是。
我认为 MSDN 文档并没有说得很清楚。以下是 WPF 的唯一相关文本。
“有关影响该值的因素的信息,请参阅 DependencyProperty。”
http:// msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.visibility(v=VS.100).aspx
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
发布评论
评论(4)
依赖属性在定义它们的类上有一个相应的静态字段。请查看 DataGridTextColumn 类。
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.
在大多数情况下,您可以通过检查是否存在类型为
DependencyProperty
的名为FooProperty
的静态字段来检测属性Foo
是否是 DP。然而,这只是一个约定。不能保证所有依赖属性都遵循此模式。In most cases you can detect whether a property
Foo
is a DP by checking if there is a static field namedFooProperty
of typeDependencyProperty
. However, this is only a convention. There is no guarantee that all dependency properties will follow this pattern.已经回答了,我知道。 IE。 “TextBlock”中的“Text”属性是您可以辨别的依赖属性,因为 Intellisense 显示如下静态字段:
TextBlock.TextProperty
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
下面是一个扩展方法,它评估属性的值并返回相应的 DependencyProperty:
Here's an extension method that evaluates a property's value and also returns the corresponding DependencyProperty: