How can I show grouping in a WPF Data Grid with multiple levels?

Posted by Keith on Stack Overflow See other posts from Stack Overflow or by Keith
Published on 2010-05-07T20:03:51Z Indexed on 2010/05/07 20:08 UTC
Read the original article Hit count: 200

Filed under:
|

I am relatively new to WPF, so I understand about Styles and setters, but I am having trouble on this one.

I am using a WPF Data Grid and need to show multiple levels of grouping. I would like the 2nd and 3rd group levels to be more indented than the top level.

The following code will show group levels, but it shows them one right on top of the other and makes the fact that they are nested group levels impossible to tell.

<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Expander IsExpanded="True">
                        <Expander.Header>
                            <TextBlock Text="{Binding Path=Name}"/>
                        </Expander.Header>
                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

How can I get the group header to indent based on level?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf