Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

datagrid template column visibility binding (silverlight)

$
0
0

I know DataGridTemplateColumn it's not in the visual tree etc. But is not there some way to do this?

I found many examples (can't post link) but they don't work for me!

Thing where i try to do is: I have one data grid with many columns (22 or more) and i want relate this columns with checkboxes to can hide and show!

This is my code for one column:

<UserControl.Resources><my:VisibilityConverter x:Key="VisibilityConverter" /></UserControl.Resources><Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"><sdk:DataGrid AutoGenerateColumns="False" Height="437" HorizontalAlignment="Stretch" Name="ResultedDataGrid" VerticalAlignment="Bottom" ><sdk:DataGrid.Columns><sdk:DataGridTemplateColumn x:Name="stockCodeColumn" Visibility="{Binding ElementName=checkBox, Path=IsChecked, Converter={StaticResource VisibilityConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True" Width="*" ><sdk:DataGridTemplateColumn.HeaderStyle><Style TargetType="sdk:DataGridColumnHeader"><Setter Property="Template"><Setter.Value><ControlTemplate><TextBlock HorizontalAlignment="Center" Width="Auto" Text="Код на стока" TextWrapping="Wrap"/></ControlTemplate></Setter.Value></Setter></Style></sdk:DataGridTemplateColumn.HeaderStyle><sdk:DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock Name="StockNameTextBlock" Text="{Binding Path=Name}" VerticalAlignment="Stretch"/></DataTemplate></sdk:DataGridTemplateColumn.CellTemplate></sdk:DataGridTemplateColumn></sdk:DataGrid.Columns></sdk:DataGrid><CheckBox Content="CheckBox"  Height="16" HorizontalAlignment="Left" Margin="295,77,0,0" Name="checkBox" VerticalAlignment="Top"/></Grid></UserControl>

From this code i get this exception: "set property 'system.windows.controls.datagridcolumn.visibility' threw an exception"!

VisibilityConverter work good i have no problem with him... but the binding...

Any ideas for simple code to fix this problem!

 Thank you in advance and sorry for my english!


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>