我目前已经用一定数量的行填充了一个数据网格,并根据部门对行进行了分组。所以,我在输出中只能看到“基于部门的分组数据网格”。
是否可以在数据网格行的分组和非分组之间切换?
例如:如果用户不想查看基于组的记录,他将单击单选按钮,数据网格将填充行而不进行分组,反之亦然。
提前致谢。
这是 DataGrid.GroupStyle 内的示例代码:
            <DataGrid.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Path=Name}"/>
                        </StackPanel>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <Expander Margin="15 0 0 0" IsExpanded="True">
                                        <Expander.Header>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock  Foreground="white" Text="{Binding Path=emp}" FontWeight="Bold" Margin="5 0 0 0"/>
                                                <TextBlock  Foreground="white" Text="{Binding Path=empCount}" Margin="10 0 3 0"/>
                                                <TextBlock  Foreground="white" Text="emps"/>
                                            </StackPanel>
                                        </Expander.Header>
                                        <ItemsPresenter />
                                    </Expander>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </DataGrid.GroupStyle>