In a loop which sets up my WPF DataGrid columns, I want to bind the column visibility to member 'i' in my 'VisibilityList' with the following code:
var bindingColumnVisibilty = new Binding(string.Format("VisibilityList[{0}]", i));
BindingOperations.SetBinding(customBoundColumn, DataGridColumn.VisibilityProperty, bindingColumnVisibilty);
I have set the DataContext before the loop begins:
TestControlDataGrid.TestDataGrid.DataContext = dataGridSource;
The dataGridSource class contains:
public List<Visibility> VisibilityList;
This does not appear to work. Have I set up my DataContext and binding correctly? Does it matter that after this loop I set the ItemsSource with the following?
TestDataGrid.ItemsSource = dataGridSource.DataList;