GroupStyle GroupStyle GroupStyle Class

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

Syntax

Declaration

public class GroupStylepublic class GroupStylePublic Class GroupStyle
<GroupStyle />

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 summary

Initializes a new instance of the GroupStyle class.

Properties summary

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.

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.

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

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

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.

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

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

Events summary

Occurs when a property value changes.

Constructors

  • GroupStyle()
    GroupStyle()
    GroupStyle()
    GroupStyle()

    Initializes a new instance of the GroupStyle class.

    public GroupStyle()public New()Public Sub New()public GroupStyle()

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" />
    

    Property Value

  • 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" />
    

    Property Value

  • 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>
    

    Property Value

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

  • 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" />
    

    Property Value

  • 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" />
    

    Property Value

    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" .../>
    

    Property Value

    • bool
      bool
      bool

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

  • 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" />
    

    Property Value

    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"/>
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll