Ganesh Gurav

Ganesh Gurav

  • NA
  • 87
  • 31.8k

uncheck Select All chkbox if any one of chkbox is unchecked

Oct 19 2016 1:30 AM

I have a checkbox named chkSelectAll which placed in header. When I click this then all other check boxes inside my DataGrid is Checked. But I want when anyone of the checkbox inside the grid will be unchecked then this chkSelectAll Checkbox will automatically uncheck.

<DataGridTemplateColumn> Please check below code .
<DataGridTemplateColumn.Header>
<CheckBox x:Name="chkSelectAll" Content="Select All" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkCellTemp" Margin="45 2 0 0">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="IsChecked" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=chkSelectAll, Mode=TwoWay}" Value="True">
<Setter Property="IsChecked" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</CheckBox.Style>
</CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Answers (4)