GroupStyle GroupStyle GroupStyle GroupStyle Class


Defines how you want the group to look at each level.

public ref class GroupStyle : System::ComponentModel::INotifyPropertyChanged
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public class GroupStyle : System.ComponentModel.INotifyPropertyChanged
type GroupStyle = class
    interface INotifyPropertyChanged
Public Class GroupStyle
Implements INotifyPropertyChanged


The following examples show an ItemsControl that is bound to an XmlDataProvider and the code-behind content that contains the logic to add and remove grouping. When the check box is checked, the content of the ItemsControl is grouped by the Type attribute.

Each group is of type CollectionViewGroup. The GroupStyle HeaderTemplate is specified so that it appears as a TextBlock that displays the Name of each the group. In this case, the Name is either Work or Home.

<Window x:Class="GroupingSample.Window1"
    Title="Grouping Sample"
    Width="220" Height="550">

      <XmlDataProvider x:Key="myTasks" XPath="Tasks/Task">
          <Tasks xmlns="">
            <Task Name="Groceries" Priority="2" Type="Home">
              <Description>Pick up Groceries and Detergent</Description>
            <Task Name="Laundry" Priority="2" Type="Home">
              <Description>Do Laundry</Description>
            <Task Name="Email" Priority="1" Type="Work">
              <Description>Email Clients</Description>
            <Task Name="Clean" Priority="3" Type="Work">
              <Description>Clean my office</Description>
            <Task Name="Dinner" Priority="1" Type="Home">
              <Description>Get ready for family reunion</Description>
            <Task Name="Proposals" Priority="2" Type="Work">
              <Description>Review new budget proposals</Description>

    <TextBlock Margin="12,5,5,0" FontSize="20" Text="My Task List"/>
    <CheckBox Margin="10,5,5,10" Checked="AddGrouping"
              Unchecked="RemoveGrouping">Group by task type</CheckBox>
    <ItemsControl Margin="10" Name="myItemsControl"
                  ItemsSource="{Binding Source={StaticResource myTasks}}">
            <Style TargetType="TextBlock">
              <Setter Property="FontSize" Value="18"/>
              <Setter Property="HorizontalAlignment" Value="Center"/>
            <Ellipse Fill="Silver"/>
              <TextBlock Margin="3,3,3,0"
                         Text="{Binding XPath=@Name}"/>
              <TextBlock Margin="3,0,3,7"
                         Text="{Binding XPath=@Priority}"/>
          <Setter Property="Control.Width" Value="100"/>
          <Setter Property="Control.Margin" Value="5"/>
              <TextBlock FontWeight="Bold" FontSize="15"
                         Text="{Binding Path=Name}"/>
using System;
using System.Windows;
using System.Windows.Data;

namespace GroupingSample
    public partial class Window1 : System.Windows.Window

        public Window1()

        CollectionView myView;
        private void AddGrouping(object sender, RoutedEventArgs e)
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
            if (myView.CanGroup == true)
                PropertyGroupDescription groupDescription
                    = new PropertyGroupDescription("@Type");

        private void RemoveGrouping(object sender, RoutedEventArgs e)
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);

Imports System.Windows
Imports System.Windows.Data

Namespace GroupingSample
    Partial Public Class Window1
        Inherits System.Windows.Window

        Public Sub New()
        End Sub

        Private myView As CollectionView
        Private Sub AddGrouping(ByVal sender As Object, ByVal e As RoutedEventArgs)
            myView = CType(CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource), CollectionView)
            If myView.CanGroup = True Then
                Dim groupDescription As New PropertyGroupDescription("@Type")
            End If
        End Sub

        Private Sub RemoveGrouping(ByVal sender As Object, ByVal e As RoutedEventArgs)
            myView = CType(CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource), CollectionView)
        End Sub
    End Class
End Namespace


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

Initializes a new instance of the GroupStyle class.


DefaultGroupPanel DefaultGroupPanel DefaultGroupPanel DefaultGroupPanel

Identifies the default ItemsPanelTemplate that creates the panel used to layout the items.


AlternationCount AlternationCount AlternationCount AlternationCount

Gets or sets the number of alternating GroupItem objects.

ContainerStyle ContainerStyle ContainerStyle ContainerStyle

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

ContainerStyleSelector ContainerStyleSelector ContainerStyleSelector ContainerStyleSelector

Enables the application writer to provide custom selection logic for a style to apply to each generated GroupItem.

Default Default Default Default

Gets the default style of the group.

HeaderStringFormat HeaderStringFormat HeaderStringFormat HeaderStringFormat

Gets or sets a composite string that specifies how to format the header if it is displayed as a string.

HeaderTemplate HeaderTemplate HeaderTemplate HeaderTemplate

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

HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector

Enables the application writer to provide custom selection logic for a template that is used to display the group header.

HidesIfEmpty HidesIfEmpty HidesIfEmpty HidesIfEmpty

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

Panel Panel Panel Panel

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


Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs)

Raises the PropertyChanged event using the provided arguments.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)


PropertyChanged PropertyChanged PropertyChanged PropertyChanged

Occurs when a property value changes.

Explicit Interface Implementations

INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged

Occurs when a property value changes.

Applies to

See also