DataGrid 分组后问题

时间:2022-04-12 16:17:17
想要实现如下效果,使用DataGrid的分组功能基本都搞定,但是如果取消勾选一个charge, 确不能将Category的checkbox取消勾选。不知该如何解决
DataGrid 分组后问题

XAML:


                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander  IsExpanded="{Binding DataContext.AreAllGroupsExpanded, RelativeSource={RelativeSource AncestorType={x:Type local:UserControl1}}, UpdateSourceTrigger= PropertyChanged}"
                                                  >
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox Name="chGroup"  Tag="{Binding Path=Name}" Checked="CheckBox_Checked"></CheckBox>
                                                    <TextBlock Text="{Binding Path=Name}" />
                                                    
                                                </StackPanel>
                                            </Expander.Header>

                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>


                                        </Expander>

                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>

2 个解决方案

#1


http://blog.csdn.net/duanzi_peng/article/details/17094639
你需要获取模板中的孩子集合,也就是checkbox集合,再复制。

#2


再复制-》再赋值checked属性

#1


http://blog.csdn.net/duanzi_peng/article/details/17094639
你需要获取模板中的孩子集合,也就是checkbox集合,再复制。

#2


再复制-》再赋值checked属性