GroupStyle GroupStyle GroupStyle Class

Definition

Describes how to display the grouped items in a collection, such as the collection from GroupItems.

public class GroupStylepublic class GroupStylePublic Class GroupStyle
<GroupStyle />
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

A GroupStyle is typically defined in Extensible Application Markup Language (XAML) and then set as the value of the GroupStyle property to define the visual look of the groups.

Examples

Here, a GroupStyle is applied to a GridView control that contains grouped data. For more info, and to see the full example code, see How to group items in a list or grid.

<GridView ItemsSource="{Binding Source={StaticResource cvsProjects}}" 
  Margin="0,120,0,0" MaxHeight="500" Grid.Column="1">
    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="20">
                <TextBlock Text="{Binding Name}" FontWeight="Bold" 
                           Style="{StaticResource BaseTextBlockStyle}"/>
                <TextBlock Text="{Binding DueDate}" TextWrapping="NoWrap" 
                           Style="{StaticResource BodyTextBlockStyle}" />
                <CheckBox Content="Complete" IsChecked="{Binding Complete}" 
                          IsEnabled="False"/>
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="3"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    <GridView.GroupStyle>
        <GroupStyle HidesIfEmpty="True">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid Background="LightGray" Margin="0">
                        <TextBlock Text='{Binding Name}' 
                                   Foreground="Black" Margin="30"
                                   Style="{StaticResource HeaderTextBlockStyle}"/>
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>

        </GroupStyle>
    </GridView.GroupStyle>
</GridView>

Constructors

GroupStyle() GroupStyle() GroupStyle() GroupStyle()

Initializes a new instance of the GroupStyle class.

public GroupStyle()public New()Public Sub New()public GroupStyle()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

ContainerStyle ContainerStyle ContainerStyle ContainerStyle

Note

ContainerStyle may be altered or unavailable for releases after Windows 8.1 and is not supported for GroupStyle.

Gets or sets the style that is applied to the GroupItem generated for each item.

public Style ContainerStyle { get; set; }public Style ContainerStyle { get; set; }Public ReadWrite Property ContainerStyle As Stylepublic Style ContainerStyle { get; set; }
<GroupStyle ContainerStyle="styleReference" />
Value
Style Style Style

The style that is applied to the GroupItem generated for each item. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

ContainerStyleSelector ContainerStyleSelector ContainerStyleSelector ContainerStyleSelector

Note

ContainerStyleSelector may be altered or unavailable for releases after Windows 8.1 and is not supported for GroupStyle.

Gets or sets a reference to a custom StyleSelector logic class. The StyleSelector referenced by this property returns a style to apply to each generated GroupItem.

public StyleSelector ContainerStyleSelector { get; set; }public StyleSelector ContainerStyleSelector { get; set; }Public ReadWrite Property ContainerStyleSelector As StyleSelectorpublic StyleSelector ContainerStyleSelector { get; set; }
<GroupStyle ContainerStyleSelector="styleSelectorReference" />
Value
StyleSelector StyleSelector StyleSelector

An object that derives from StyleSelector. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

HeaderContainerStyle HeaderContainerStyle HeaderContainerStyle HeaderContainerStyle

Gets or sets the style that is applied to the header for each item.

public Style HeaderContainerStyle { get; set; }public Style HeaderContainerStyle { get; set; }Public ReadWrite Property HeaderContainerStyle As Stylepublic Style HeaderContainerStyle { get; set; }
<GroupStyle ...>
  <GroupStyle.HeaderContainerStyle>
    <Style TargetType="headerItemType">
      oneOrMoreSetters
    </Style>
  </GroupStyle.HeaderContainerStyle>
</GroupStyle>
Value
Style Style Style

The style that is applied to the header for each item. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

HeaderTemplate HeaderTemplate HeaderTemplate HeaderTemplate

Gets or sets the template that is used to display the group header.

public DataTemplate HeaderTemplate { get; set; }public DataTemplate HeaderTemplate { get; set; }Public ReadWrite Property HeaderTemplate As DataTemplatepublic DataTemplate HeaderTemplate { get; set; }
<GroupStyle HeaderTemplate="dataTemplateReference" />
Value
DataTemplate DataTemplate DataTemplate

A DataTemplate object that is used to display the group header. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector

Gets or sets a reference to a custom DataTemplateSelector logic class. The DataTemplateSelector returns different DataTemplate values to use for the header area of group item content.

public DataTemplateSelector HeaderTemplateSelector { get; set; }public DataTemplateSelector HeaderTemplateSelector { get; set; }Public ReadWrite Property HeaderTemplateSelector As DataTemplateSelectorpublic DataTemplateSelector HeaderTemplateSelector { get; set; }
<GroupStyle HeaderTemplateSelector="dataTemplateSelectorReference" />
Value
DataTemplateSelector DataTemplateSelector DataTemplateSelector

An object that derives from DataTemplateSelector. The default is null.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

For example XAML that references a custom DataTemplateSelector as the HeaderTemplateSelector value, and example code that shows the overrides for HeaderTemplateSelector methods, see How to group items in a list or grid.

HidesIfEmpty HidesIfEmpty HidesIfEmpty HidesIfEmpty

Gets or sets a value that indicates whether items corresponding to empty groups should be displayed.

public bool HidesIfEmpty { get; set; }public bool HidesIfEmpty { get; set; }Public ReadWrite Property HidesIfEmpty As boolpublic bool HidesIfEmpty { get; set; }
<GroupStyle HidesIfEmpty="bool" .../>
Value
bool bool bool

True to not display empty groups; otherwise, false. The default is false.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Panel Panel Panel Panel

Gets or sets a template that creates the panel used to lay out the items.

public ItemsPanelTemplate Panel { get; set; }public ItemsPanelTemplate Panel { get; set; }Public ReadWrite Property Panel As ItemsPanelTemplatepublic ItemsPanelTemplate Panel { get; set; }
<GroupStyle Panel="itemsPanelTemplateReference" />
Value
ItemsPanelTemplate ItemsPanelTemplate ItemsPanelTemplate

An ItemsPanelTemplate object that creates the panel used to layout the items.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

An ItemsPanelTemplate object element should contain exactly one FrameworkElement -derived class that serves as the root element for items. In most cases this is a Panel -derived class. The expanded template serves as the parent for the realized items and there generally is more than one item. Therefore the XAML content property of the intended root element of an ItemsPanelTemplate should support a collection, as Children does.

Important

The root element of the template declared for the ItemsPanelTemplate in the Panel property cannot be a virtualizing panel. Virtualizing panels are defined as any type that derives from VirtualizingPanel, for example the VirtualizingStackPanel class.

Events

PropertyChanged PropertyChanged PropertyChanged PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler PropertyChangedpublic event PropertyChangedEventHandler PropertyChangedPublic Event PropertyChangedpublic event PropertyChangedEventHandler PropertyChanged
<GroupStyle PropertyChanged="eventhandler"/>
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)