DataGrid Group style issue ?

Nov 10, 2008 at 6:59 AM
Hi,

 I  used to use this GroupStyle in my grid:

<GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Margin" Value="0,0,0,5"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True" Style="{StaticResource ExpanderGroupStyle}">
                                            <Expander.Header>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*"/>
                                                        <ColumnDefinition />
                                                    </Grid.ColumnDefinitions>

                                                    <TextBlock Text="{Binding Path=Name}" Margin="5,0,5,0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" FontFamily="Tahoma" FontWeight="Bold" Foreground="{StaticResource TitleLabelBrush}" FontSize="11" />
                                                    <TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                                                        <TextBlock FontFamily="Tahoma" FontWeight="Bold" FontSize="11" Foreground="{StaticResource TitleLabelBrush}" Text="{Binding Path=ItemCount}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                        <TextBlock FontFamily="Tahoma"  FontWeight="Bold" Text="{Binding Path=groupItems, Source={StaticResource Strings}}" FontSize="11" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{StaticResource TitleLabelBrush}" />
                                                    </TextBlock>
                                                </Grid>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>

But with v1 this does not seem to work anymore.
Does anybody have an ideea regarding this ?

Thank you,
Calin,
Nov 10, 2008 at 12:55 PM
Hi, I tried many variants and make this realzation from non-related sources

            <kit:DataGrid.GroupStyle>
                <GroupStyle>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <primitives:DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Padding="3"/>
                            </StackPanel>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="False"
                                                  BorderBrush="#FFA4B97F" 
                                                  BorderThickness="0,0,0,1"
                                                  >
                                            <Expander.Header>
                                                <DockPanel TextBlock.FontWeight="Bold">
                                                    <TextBlock Text="{Binding Path=Name}" 
                                                               Margin="5,0,5,0"
                                                               />
                                                    <TextBlock Text="{Binding Path=ItemCount}"/>
                                                </DockPanel>
                                            </Expander.Header>
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </kit:DataGrid.GroupStyle>


Nov 11, 2008 at 7:03 AM
Thank you,

 It works perfect,

Regards,
Calin
Nov 12, 2008 at 7:56 AM
You are welcome. 

But I appeared before one intresting problem. 
I don't know how to set GroupStyle in the Style of DataGrid on the stage of making control library.
This GroupStyle needs to be default style in control library .... 
Now I can apply this style only on the stage of using.
Can somebody help me to resolve this situation?
Coordinator
Nov 13, 2008 at 2:25 PM
I don't quite follow.  You want to dynamically set the GroupStyle of the DataGrid?
Nov 13, 2008 at 2:33 PM
I want set my GroupStyle as default style in my derived DataGrid in theme part of my control library. 

Jan 4, 2009 at 4:36 PM
Hi,
I am having a similar problem...  I have styled by own DataGrid (myDataGridStyle) in my resource dictionary, and I have a default grouping style in the same resource dictionary; however, I cannot seem to get that grouping style to work if defined inside myDataGridStyle.  The only way I can get it to work is if I specify GroupStyle ContainerStyle="{StaticResource GroupContainerStyle}" as part of the DataGrid instance definition.  XAML snippet is below.  Please help.

Thanks in advance,
E.

        <dg:DataGrid x:Name="myDataGrid"
                     DockPanel.Dock="Top"
                     Margin="5,5,5,5"
                     Background="#FFFCFCFC"
                     HorizontalScrollBarVisibility="Auto"
                     VerticalScrollBarVisibility="Auto"
                     GridLinesVisibility="None"
                     AlternationCount="2"
                     RowHeaderWidth="30"
                     Style="{DynamicResource myDataGridStyle}">
                     
            <dg:DataGrid.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource GroupContainerStyle}">
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <dgp:DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </dg:DataGrid.GroupStyle>

        </dg:DataGrid>

Jan 4, 2009 at 10:17 PM
To be clear, I would like the GroupStyle definition to be inside my DataGrid control template - but I can't seem to get the GroupStyle setter property to work.  Any help is greatly appreciated.

Thanks.

    <Style x:Key="myDataGridStyle" TargetType="{x:Type Custom:DataGrid}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="BorderBrush" Value="#FF688CAF"/>
        <Setter Property="BorderThickness" Value="1,1,1,1"/>
        <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Custom:DataGrid}">
                   ...
                   ...
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>