GroupStyle::HeaderStringFormat Property

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

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public:
property String^ HeaderStringFormat {
	String^ get ();
	void set (String^ value);
}
<object HeaderStringFormat="string" .../>

Property Value

Type: System::String
A composite string that specifies how to format the header if it is displayed as a string.

HeaderStringFormat can be a predefined, composite, or custom string format. For more information about string formats, see Formatting Types in the .NET Framework. If you set the HeaderTemplate or HeaderTemplateSelector property of a GroupStyle, the HeaderStringFormat property is ignored.

The following example creates a ListBox that groups a collection of items by price range. The converter, GroupByPrice, returns an integer value that is above each item's price. For example, if an item's price is between 0 and 100, the converter returns 100. The example uses the HeaderStringFormat to create a string that includes the upper limit for each price range. For example, in the United States, items that are under 100 dollars are grouped under a heading that says "Items under $100".

<StackPanel>
  <StackPanel.Resources>

      <src:ItemsForSale x:Key="MyData"/>
      <src:GroupByPrice x:Key="GroupByPrice"/>

      <CollectionViewSource x:Key="PriceGroup" Source="{StaticResource MyData}">

        <CollectionViewSource.GroupDescriptions>
          <PropertyGroupDescription PropertyName="Price"
                                    Converter="{StaticResource GroupByPrice}"/>
      </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>
  </StackPanel.Resources>

  <ListBox ItemsSource="{Binding Source={StaticResource PriceGroup}}"
           DisplayMemberPath="Description">
    <ListBox.GroupStyle>
      <GroupStyle HeaderStringFormat="Items under {0:c}"/>
    </ListBox.GroupStyle>
  </ListBox>
</StackPanel>

The following example shows the GroupByPrice class, the PurchaseItem class, and the collection that the ListBox is bound to.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft