I have placed a checkbox control in an auto-generated WPF datagrid ColumnHeaderStyle as shown below:
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox x:Name="HeaderCheckBox" Content="{Binding}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>
How could I access the CheckBox in code behind? There would be multiple columns in datagrid, how could I find out (column-wise) checkbox is selected or not ?
Please suggest.
Just add the events Checked
and Unchecked
and once you checked it the event ll be raised
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox x:Name="HeaderCheckBox" Content="{Binding}"
Checked="CheckBoxChanged" Unchecked="CheckBoxChanged"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.ColumnHeaderStyle>