Silverlight DataGridTextColumn Binding Visibility
Asked Answered
O

3

7

Following my earlier post I am now trying now to bind the visibility of DataGridColumns to a VM notification property. MSDN suggests I should be able to do this with ease.

I already have a value convertor and VM notification property that I know works (I have tested these on another element on my page:

<CheckBox x:Name="chkAllTeams" Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter}, Path=AllTeams}"/>

This checkbox control visibility reacts as I would expect. When I set the same binding on the DataTextColumn I get an AG_E_BAD_PARSER error on the Visibility= line of XAML:

<data:DataGridTextColumn 
Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter}, Path=AllTeams}"
/>

Any ideas anyone? Thanks, Mark

Orling answered 11/6, 2009 at 19:56 Comment(0)
S
9

Visibility on the DataGridTextColumn is a different beast on the checkbox. Basically, it isn't a dependency property and can't be data-bound. If you need this functionality, you can subclass DataGridTextColumn and add your own dependency property to get the behavior.

  • Rectangle gets its Visibility property from UIElement and is a dependency property
  • DataGridTextColumn gets its Visibility from DataGridColumn and isn't a dependency property.
Slaughterhouse answered 11/6, 2009 at 20:26 Comment(4)
Ah this is what I expected :-( Is that an easy task to subclass the DataGridTextColumn? Do you know of any online example for that? MarkOrling
I don't know of any particular examples for DataGridTextColumn. The general approach would be to subclass, add a new dependency property for visibility and then use the new subclass in the Datagrid.Columns . Jesse has a good explanation of dependency properties: silverlight.net/blogs/jesseliberty/archive/2008/09/30/…Slaughterhouse
That link is dead now, this is the new one: jesseliberty.com/2008/09/30/…Epigraphic
how about using an attached property instead?Powdery
G
-1

Did you set BoolToVisibilityConverter as a resource?

Grandparent answered 11/6, 2009 at 19:59 Comment(2)
Yep. Previous example on the checkbox proves that.Orling
actually your example only shows half the code... anyway, as others have said that might not be your problem. <Grid.Resources> <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" /> </Grid.Resources>Grandparent
T
-2

You'll need to use a datatemplate:

<DataTemplate x:Key="cBDT">
<(UIELEMENT HERE) x:Name="chkAllTeams" Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter}, Path=AllTeams}"/> </DataTemplate>

As was mentioned before, only UIElement has the "Visibility" dependency property.

To see an example of this in context:

http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx

Tapley answered 11/6, 2009 at 23:5 Comment(1)
Not a good answer - this hides the element in the column, not the column itself.Otherness

© 2022 - 2024 — McMap. All rights reserved.