PropertyGroupDescription Class

Describes the grouping of items using a property name as the criteria.

System.Object
  System.ComponentModel.GroupDescription
    System.Windows.Data.PropertyGroupDescription

Namespace:  System.Windows.Data
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 class PropertyGroupDescription : GroupDescription
<PropertyGroupDescription .../>

The PropertyGroupDescription type exposes the following members.

  NameDescription
Public methodPropertyGroupDescription()Initializes a new instance of the PropertyGroupDescription class.
Public methodPropertyGroupDescription(String)Initializes a new instance of the PropertyGroupDescription class with the specified property name.
Public methodPropertyGroupDescription(String, IValueConverter)Initializes a new instance of the PropertyGroupDescription class with the specified property name and converter.
Public methodPropertyGroupDescription(String, IValueConverter, StringComparison)Initializes a new instance of the PropertyGroupDescription class with the specified parameters.
Top

  NameDescription
Public propertyConverterGets or sets a converter to apply to the property value or the item to produce the final value that is used to determine which group(s) an item belongs to.
Public propertyGroupNamesGets the collection of names that are used to initialize a group with a set of subgroups with the given names. (Inherited from GroupDescription.)
Public propertyPropertyNameGets or sets the name of the property that is used to determine which group(s) an item belongs to.
Public propertyStringComparisonGets or sets a StringComparison value that specifies the comparison between the value of an item (as determined by PropertyName and Converter) and the name of a group.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGroupNameFromItemReturns the group name(s) for the given item. (Overrides GroupDescription.GroupNameFromItem(Object, Int32, CultureInfo).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodNamesMatchReturns a value that indicates whether the group name and the item name match so that the item belongs to the group. (Overrides GroupDescription.NamesMatch(Object, Object).)
Protected methodOnPropertyChangedRaises the PropertyChanged event. (Inherited from GroupDescription.)
Public methodShouldSerializeGroupNamesReturns whether serialization processes should serialize the effective value of the GroupNames property on instances of this class. (Inherited from GroupDescription.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Protected eventPropertyChangedOccurs when a property value changes. (Inherited from GroupDescription.)
Top

  NameDescription
Explicit interface implemetationPrivate eventINotifyPropertyChanged.PropertyChangedOccurs when a property value changes. (Inherited from GroupDescription.)
Top

Views support the functionality of grouping, which allows the user to partition the collection in the collection view into logical groups. The groups can be explicit, where the user supplies a list of groups, or implicit, where the groups are generated dynamically depending on the data.

PropertyGroupDescription allows you to create implicit groups based on a PropertyName. If you simply want to group by a property you can set the PropertyName property. If you want to change the value that is eventually used for group you can use the Converter property to supply a value converter. For example, you may want to group items based on the first letter of a name. If the PropertyName property is not set, the item itself is passed to the value converter. The converter may return a collection, which indicates the items can appear in more than one group.

You can also define how string comparison should take place using the StringComparison property.

This example shows how to create a view of a data collection in Extensible Application Markup Language (XAML). Views allow for the functionalities of grouping, sorting, filtering, and the notion of a current item.

In the following example, the static resource named places is defined as a collection of Place objects, in which each Place object is consisted of a city name and the state. The prefix src is mapped to the namespace where the data source Places is defined. The prefix scm maps to "clr-namespace:System.ComponentModel;assembly=WindowsBase" and dat maps to "clr-namespace:System.Windows.Data;assembly=PresentationFramework".

The following example creates a view of the data collection that is sorted by the city name and grouped by the state.

  <Window.Resources>

    <src:Places x:Key="places"/>

    <CollectionViewSource Source="{StaticResource places}" x:Key="cvs">
      <CollectionViewSource.SortDescriptions>
        <scm:SortDescription PropertyName="CityName"/>
      </CollectionViewSource.SortDescriptions>
      <CollectionViewSource.GroupDescriptions>
        <dat:PropertyGroupDescription PropertyName="State"/>
      </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

The view can then be a binding source, as in the following example:

<ListBox ItemsSource="{Binding Source={StaticResource cvs}}"
         DisplayMemberPath="CityName" Name="lb">
  <ListBox.GroupStyle>
    <x:Static Member="GroupStyle.Default"/>
  </ListBox.GroupStyle>
</ListBox>

For bindings to XML data defined in an XmlDataProvider resource, precede the XML name with an @ symbol.

<XmlDataProvider x:Key="myTasks" XPath="Tasks/Task">
    <x:XData>
        <Tasks xmlns="">
            <Task Name="Groceries" Priority="2" Type="Home">
<CollectionViewSource x:Key="mySortedTasks"
                      Source="{StaticResource myTasks}">
    <CollectionViewSource.SortDescriptions>
        <scm:SortDescription PropertyName="@Priority" />
    </CollectionViewSource.SortDescriptions>
    <CollectionViewSource.GroupDescriptions>
        <dat:PropertyGroupDescription PropertyName="@Priority" />
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft