Piotr Sidor

Piotr Sidor

  • NA
  • 27
  • 795

How to get access to gruop style element in datagrid.

Jul 30 2019 6:31 AM
 I have implement datagrid as below and i have no idea how to with checkbox named SelectGroupCheckBox check all checkbox in gruop.
 
  1. <DataGrid x:Name="PersonDataGrid"    
  2.                   HorizontalAlignment="Left"   
  3.                   VerticalAlignment="Top"   
  4.                   Height="450" Width="902"     
  5.                   CanUserAddRows="False"   
  6.                   AutoGenerateColumns="False" >  
  7.             <DataGrid.GroupStyle>  
  8.                 <GroupStyle>  
  9.                     <GroupStyle.ContainerStyle>  
  10.                         <Style TargetType="{x:Type GroupItem}">  
  11.                             <Setter Property="Template">  
  12.                                 <Setter.Value>  
  13.                                     <ControlTemplate TargetType="{x:Type GroupItem}">  
  14.                                         <Expander IsExpanded="False">  
  15.                                             <Expander.Header>  
  16.                                                 <StackPanel Orientation="Horizontal">  
  17.                                                     <CheckBox x:Name="SelectGroupCheckBox" >  
  18.                                                           
  19.                                                     </CheckBox>  
  20.                                                     <TextBlock Text="{Binding Name}"/>  
  21.                                                 </StackPanel>  
  22.                                             </Expander.Header>  
  23.                                             <Expander.Content>  
  24.                                                 <ItemsPresenter/>  
  25.                                             </Expander.Content>  
  26.                                         </Expander>  
  27.                                     </ControlTemplate>  
  28.                                 </Setter.Value>  
  29.                             </Setter>  
  30.                         </Style>  
  31.                     </GroupStyle.ContainerStyle>  
  32.                 </GroupStyle>  
  33.             </DataGrid.GroupStyle>  
  34.             <DataGrid.Columns>  
  35.                 <DataGridTemplateColumn>  
  36.                     <DataGridTemplateColumn.Header>  
  37.                         <CheckBox Content="Select All"   
  38.                                   Checked="CheckBox_Checked"   
  39.                                   Unchecked="CheckBox_Unchecked"/>  
  40.                     </DataGridTemplateColumn.Header>  
  41.                     <DataGridTemplateColumn.CellTemplate>  
  42.                         <DataTemplate>  
  43.                             <CheckBox IsChecked="{Binding IsSelected,   
  44.                                                   Mode=TwoWay,   
  45.                                                   UpdateSourceTrigger=PropertyChanged}"/>  
  46.                         </DataTemplate>  
  47.                     </DataGridTemplateColumn.CellTemplate>  
  48.                 </DataGridTemplateColumn>  
  49.                 <DataGridTextColumn Binding="{Binding Person.Name}"   
  50.                                     Header="Name"   
  51.                                     Width="120"   
  52.                                     IsReadOnly="True"/>  
  53.             </DataGrid.Columns>  
  54.         </DataGrid> 

Answers (1)