This is a migrated thread and some comments may be shown as answers.

GridView GroupStyle

1 Answer 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 29 Mar 2014, 10:53 AM
Hello,

I have bought the Terelik DevCraft package and now I am working to convert some of my controls to Telerik controls.
I started with a DataGrid, this DataGrid has a GroupStyle and I am trying to  apply this groupstyle to my new GridView.
The groupstyle has a converter which checks if the group contains more than 1 items, then it wil create a groupbox around the item with a header which specificies to which order the items belong. When there is only 1 item in the group there is no groupbox and no header.

I want to have the same functionality in my new GridView, my new GridView already group the items by ordernumber in an expander, I am now a bit lost on how to style the header so it shows the same information as my former groupstyle. Because of the expander of the GridView its not necessary to use a groupbox anymore.

My old groupstyle:

                    <DataGrid.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        
                                    </StackPanel>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.ContainerStyle>
                                <Style TargetType="{x:Type GroupItem}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=Items, Converter={StaticResource groupDocumentsConverter}}" Value="True">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                                        <GroupBox Margin="2,20,2,25">
                                                            <GroupBox.HeaderTemplate>
                                                                <DataTemplate>
                                                                    <StackPanel VirtualizingStackPanel.IsVirtualizing="True" Orientation="Horizontal" DataContext="{Binding Path=DataContext, 
                                                                                    RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=GroupItem}}">
                                                                        <TextBlock Text="Order " FontWeight="Bold" />
                                                                        <TextBlock Text="{Binding Path=Name, StringFormat='{}{0:000000}'}" FontWeight="Bold"/>
                                                                        <TextBlock Text=" - " FontWeight="Bold"/>
                                                                        <TextBlock Text="{Binding Path=ItemCount}" FontWeight="Bold"/>
                                                                        <TextBlock Text=" document(s)" FontWeight="Bold"/>
                                                                    </StackPanel>
                                                                </DataTemplate>
                                                            </GroupBox.HeaderTemplate>
                                                            <ItemsPresenter />
                                                        </GroupBox>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </GroupStyle.ContainerStyle>
                        </GroupStyle>
                    </DataGrid.GroupStyle>

I searched in the documentation on internet but wasnt able to find a good solution.
The documentation points me to altering the template using Blend, but I think a faster solution should be possible?

Any help would be greatly appreciated.

Marcel


                    





1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 02 Apr 2014, 03:36 PM
Hello Marcel,

If you want to style conditionally RadGridView group rows, you can use GroupRowStyleSelector as shown in this online demo. The same example is available in your local copy of WPF demos. Extended example for using a style selector can be found in the RowStyleSelector help article. The approach for the group row will be similar. Also, if you want to predefine the template of RadGridView's group row template, you can use the GroupHeaderTemplate property:
<telerik:RadGridView Grid.Row="0"
     Name="clubsGrid"
     ItemsSource="{Binding Clubs}"
     AutoGenerateColumns="False"
     Margin="5">
            <telerik:RadGridView.GroupHeaderTemplate>
                <DataTemplate>
                     
                </DataTemplate>
            </telerik:RadGridView.GroupHeaderTemplate>

I hope this information helps.

Regards,
Yoan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Marcel
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or