I am new to WPF and would appreciate help on following problem.
In my wpf datagrid I have DataGridCheckBoxColumn as first column and I have bind this column to IsSelected property in ViewModel.
<toolkit:DataGridCheckBoxColumn Header="Title" Binding="{Binding isSelected}"/>
I also want to have a checkbox in header row and which I intend to use to select/unselect all the checkboxes in this column.
Till now I have managed to get a checkbox in header by applying a headerstyle as shown in below code snip but I am not able to toggle selection for all the checkboxes in column
<Style x:Key="CheckBoxHeaderStyle" TargetType="{x:Type toolkit:DataGridColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type toolkit:DataGridColumnHeader}">
<CheckBox x:Name="chkToggleSelection" VerticalAlignment="Center">
</CheckBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You will have to handle the Checkbox.Click
event (if you are using MVVM then set the CheckBox.Command
or use attached behavior to handle the event) and then set the boolean property of all items bound to the datagrid as true \ false accordingly.
Sadly there is no other alternative that I am aware of!