mercredi 29 juin 2016

How to fire click event of checkbox in a datagrid expander header

I have a datagrid with 3 level grouping. Grouping is done in code behind using the CollectionView and PropertyGroupDescription. Every row of record will have a DataTemplateColumn (CheckBox). I would like to include a checkbox infront of each header so that I can check all the child data. Unfortunately I have tried few methods but it does not work.

xaml codes

<DataGrid.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Expander x:Name="MyExpander" IsExpanded="True">
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox Click="checkBoxHeader_Click"/>
                                                    <TextBlock x:Name="MyExpanderHeader" Text="{Binding Name}" FontWeight="Bold" VerticalAlignment="Bottom">
                                                    </TextBlock>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ItemsPresenter Margin="20,0,0,0"/>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>

cs code

CollectionView collectionView = (CollectionView)CollectionViewSource.GetDefaultView(m_stationInfoList);
            PropertyGroupDescription groupDescription1 = new PropertyGroupDescription("Property1");
            PropertyGroupDescription groupDescription2 = new PropertyGroupDescription("Property2");
            PropertyGroupDescription groupDescription3 = new PropertyGroupDescription("Property3");
            collectionView.GroupDescriptions.Clear();
            collectionView.GroupDescriptions.Add(groupDescription1);
            collectionView.GroupDescriptions.Add(groupDescription2);
            collectionView.GroupDescriptions.Add(groupDescription3);




Aucun commentaire:

Enregistrer un commentaire