Как сгруппировать Datagrid без расширителя

Я работаю с примером группировки Datagrid здесь, в MSDN. Код в примере использует Expander для отображения дочерних строк группы. Я не хочу использовать Expander в своем коде. Я хочу всегда отображать каждую строку. Как отобразить дочерние строки в сгруппированной сетке данных без использования элемента управления Expander?


person user1214135    schedule 17.12.2012    source источник


Ответы (1)


Вместо использования Expander вы можете использовать Border.

 <DataGrid.GroupStyle>
                <!-- Style for groups at top level. -->
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Margin" Value="0,0,0,0"/>                            
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">   
                                        <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5,5,5,5" Margin="0,0,0,5">
                                            <StackPanel>
                                                <StackPanel Height="30" Orientation="Horizontal">
                                                    <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100" VerticalAlignment="Center"/>
                                                    <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}" VerticalAlignment="Center" />
                                                </StackPanel>

                                                <ItemsPresenter />
                                            </StackPanel>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
                <!-- Style for groups under the top level. -->
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <DockPanel Background="LightBlue">
                                <TextBlock Text="{Binding Path=Name, Converter={StaticResource completeConverter}}" Foreground="Blue" Margin="30,0,0,0" Width="100"/>
                                <TextBlock Text="{Binding Path=ItemCount}" Foreground="Blue"/>
                            </DockPanel>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
 </DataGrid.GroupStyle>
person kmatyaszek    schedule 17.12.2012