dimanche 8 février 2015

WPF DataGrid Add select all checkbox in Header in code behind

I am adding dynamically checkbox columns to WPF datagrid based on user interactions (button clicks, checkboxes etc). I need also to add an Select all checkbox to column header programmatically. Any ideas how to do it?



DataGridCheckBoxColumn checkBoxColumn=new DataGridCheckBoxColumn();
checkBoxColumn.Header = "Title";
checkBoxColumn.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
checkBoxColumn.Binding = new Binding(e.PropertyName);
checkBoxColumn.IsThreeState = true;


I would do it through XAML it should look something like this



<DataGridTemplateColumn>
<DataGridTemplateColumn.Header>
<CheckBox isChecked="{Binding SelectAll}"></CheckBox>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<CheckBox IsChecked="{Binding MyRowCheckProperty}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>




Aucun commentaire:

Enregistrer un commentaire