为什么不能在Silverlight 4中绑定DataGridTemplateColumn的Visiblity? [英] Why can I not bind the Visiblity of a DataGridTemplateColumn in Silverlight 4?
问题描述
似乎不可能在Silverlight 4中绑定DataGridTemplateColumn的visibility属性。我做了一些谷歌搜索,似乎有几个帖子表明它是做与事实上它不是DependencyObject ,以及这会在SL4中如何变化,但是这似乎不是这样的。
It seems that it is not possible to bind the visibility property of a DataGridTemplateColumn in Silverlight 4 still. I did some Googling and there seem to be a few posts suggesting it was to do with the fact that it was not a DependencyObject and how this would change in SL4 but it does not seem to be the case.
为了解决这个问题,我在datagrid加载的事件的代码中做到这一点,但是我很好奇为什么这样是这样吗?
To work around it, I do it in the code behind of the datagrid loaded event, but I am curious as to why this is the case?
这是我得到的错误消息(转换器返回Visibility值):
Here is the error message I get (with a converter that returns a Visibility value):
{System.ArgumentException: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Windows.Visibility'.
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)}
推荐答案
DataGridTemplateColumn 从 DependencyObject
派生,它的Visibility属性没有定义一个 DependencyProperty
。实际上它没有定义任何依赖属性,因此你仍然无法获得绑定的任何东西。
Whilst the DataGridTemplateColumn
does derive from DependencyObject
it does not define a DependencyProperty
for its Visibility property. In fact it does not define any dependency properties hence you still can't get anything to bind on it.
这篇关于为什么不能在Silverlight 4中绑定DataGridTemplateColumn的Visiblity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!