This documentation is archived and is not being maintained.

GroupStyle.ContainerStyle Property

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

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public Style ContainerStyle { get; set; }
    <Style .../>
<object ContainerStyle="{ResourceExtension StyleResourceKey}"/>

XAML Values


One of the following: StaticResource, or DynamicResource. See Resources Overview.


The key that identifies the style being requested. The key refers to an existing resource in a ResourceDictionary.

Property Value

Type: System.Windows.Style
The style that is applied to the GroupItem generated for each item. The default is null.

This property is a rare case where creating a Style inline in property element syntax, rather than creating the style as a resource, is a reasonable alternative methodology.

This example shows how to display groups of items in the GridView view mode of a ListView control.

To display groups of items in a ListView, define a CollectionViewSource. The following example shows a CollectionViewSource that groups data items according to the value of the Catalog data field.

<CollectionViewSource x:Key='src' 
                      Source="{Binding Source={StaticResource MyData}, 
    <PropertyGroupDescription PropertyName="@Catalog" />

The following example sets the ItemsSource for the ListView to the CollectionViewSource that the previous example defines. The example also defines a GroupStyle that implements an Expander control.

<ListView ItemsSource='{Binding Source={StaticResource src}}' 
        <Style TargetType="{x:Type GroupItem}">
          <Setter Property="Margin" Value="0,0,0,5"/>
          <Setter Property="Template">
              <ControlTemplate TargetType="{x:Type GroupItem}">
                <Expander IsExpanded="True" BorderBrush="#FFA4B97F" 
                      <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" 
                                 Margin="5,0,0,0" Width="100"/>
                      <TextBlock FontWeight="Bold" 
                                 Text="{Binding Path=ItemCount}"/>
                    <ItemsPresenter />



For the complete sample, see ListView Grouping Sample.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0