views:

137

answers:

1

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.

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?

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)}
A: 

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.

AnthonyWJones
Thanks for your help as always Anthony.
Rodney