I am trying to associate the visibility property DataGridTextColumn with the value IsChecked in a combo box (cbIP). For most columns, I solved the problem in XAML with lines like this:
<DataGridTextColumn Header="Time" Binding="{Binding MeasureTime}" Visibility="{Binding Source={x:Reference cbMeasureTime}, Path=IsChecked, Converter={StaticResource BoolToVisConverter}}"></DataGridTextColumn>
However, some columns relate to values ββthat are based on variable-length arrays (and therefore different amounts of columns). I have no problem creating code. The only problem is the visibility property. I went so far:
private void Page_Loaded_1(object sender, RoutedEventArgs e) { for (int i = 0; i < ds.NumberOfIPValues; i++) { DataGridTextColumn col = new DataGridTextColumn() { Header = String.Format("IP #{0} (mV/V)", i + 1) }; col.Binding = new Binding(String.Format("IP[{0}]",i)); Binding b = new Binding("Visibility"); b.Source = cbIP; b.Path = new PropertyPath(typeof(CheckBox).GetProperty("IsChecked")); b.Converter = new BoolToVisibilityConverter(); BindingOperations.SetBinding(col, DataGridTextColumn.VisibilityProperty, b); ViewInTableDataGrid.Columns.Add(col); } }
Needless to say, this will not work. I see the columns, but the checkbox does not work. (It works for columns created by XAML.
What am I doing wrong?
Thanks in advance!
source share