WPF Datagrid grouping column header question

May 29, 2009 at 1:27 AM


I have grouped my data in a datagrid and used a customized expander to hide the toggle button. I have expanded it to the right. The result is shown below.

My question is how to access/set the value of the column header above group names?

Can someone please help on this, none of the things I have tried out helped.


Jun 3, 2009 at 10:54 PM

Here are some more details on the issue.

I have grouped my data in a datagrid but instead of the common way to use an expander, I have just used  a stackpanel with horizontal orientation.

The result is shown below.

item # 1. I am trying to set the name of the group (country in this example) above the area where the name of the countries appear.
I tried various permutations and combinations but I am not able to set the name or the width of that location.  And a major layout issue is that the header is not aligned with the body, the state/city/name headers do not appear above their columns.

item # 3. I am not sure why there is a gap between the country name ( group header ) and the rest of the datagrid.

I am including my code below for reference.

<Window x:Class="WPFSample.Window3"
    Title="Grouping" Height="547" Width="375"

        <ObjectDataProvider x:Key="ppl"
            ObjectType="{x:Type local:ppl}"
        <CollectionViewSource x:Key="cvs" Source="{Binding Source={StaticResource ppl}}">
                <PropertyGroupDescription PropertyName="Country" />

    <dg:DataGrid Background="White" Name="ChecksGrid"
                     HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"
                     AutoGenerateColumns="False" AlternationCount="2"
                     ItemsSource="{Binding Source={StaticResource cvs}}"
                     BorderThickness="0" SelectionMode="Single"
                     SelectionUnit="FullRow" GridLinesVisibility="All"
                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}"/>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <StackPanel Orientation="Horizontal">
                                        <Border BorderBrush="Black" BorderThickness="1,1,0,0.5">
                                        <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                                            <ContentPresenter Content="{Binding Path=Name}" Width="35"/>
                                        <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
            <dg:DataGridTextColumn Binding="{Binding Path=State, Mode=TwoWay}" Header="State" />
            <dg:DataGridTextColumn Binding="{Binding Path=City, Mode=TwoWay}" Header="City" />
            <dg:DataGridTextColumn Binding="{Binding Path=FirstName, Mode=TwoWay}" Header="First Name" />
            <dg:DataGridTextColumn Binding="{Binding Path=LastName, Mode=TwoWay}" Header="Last Name" />

Jul 20, 2009 at 1:49 PM

Hi ,

Even im also facing same issue.Whenever i group contents ,alignment is not maintained.Any clues on this .


With regards,


Nov 25, 2009 at 10:14 AM


Here is an usefull link:


I hope that this doesn't come to late.