Share via


CollectionViewSource.SortDescriptions Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.

Namespace:  System.Windows.Data
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public ReadOnly Property SortDescriptions As SortDescriptionCollection
public SortDescriptionCollection SortDescriptions { get; }
<collectionViewSource>
  <collectionViewSource.SortDescriptions>
    oneOrMoreSortDescriptions
  </collectionViewSource.SortDescriptions>
</collectionViewSource>

XAML Values

Term

Definition

oneOrMoreSortDescriptions

One or more SortDescription elements.

Property Value

Type: System.ComponentModel.SortDescriptionCollection
A collection of SortDescription objects that describe how the items in the collection are sorted in the view.

Remarks

This property is forwarded to any collection view created from the current Source.

Examples

The following code example demonstrates the use of this property in XAML to apply sorting to a data source. The data is also defined in XAML to enable you to see the effects of the CollectionViewSource in the Silverlight Designer in Visual Studio 2010.

This example uses the Customer and CustomerCollection classes defined in Walkthrough: Using Sample Data in the Silverlight Designer. The walkthrough also describes how to use design-time attributes to display sample data in the Silverlight Designer.

<UserControl x:Class="CollectionViewSourceExample.MainPage"
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:local="clr-namespace:DesignDataDemo"
  xmlns:compMod="clr-namespace:System.ComponentModel;assembly=System.Windows"
  xmlns:sdk="https://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
  mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" >

  <UserControl.Resources>

    <local:CustomerCollection x:Key="customerSampleData" >
      <local:Customer FirstName="Syed" LastName="Abbas" Age="23" 
        CustomerID="E7181DC6-3F9E-45A4-A5F7-AC0B119D1FD8" />
      <local:Customer FirstName="Brenda" LastName="Diaz" Age="55" 
        CustomerID="BB638D72-8B72-495A-B0F9-79F37964BBAE" />
      <local:Customer FirstName="Lori" LastName="Kane" Age="17" 
        CustomerID="B168D811-5548-4D28-8171-318F9A4D7219" />
    </local:CustomerCollection>

    <CollectionViewSource x:Name="dataSource" 
      Source="{StaticResource customerSampleData}">
      <CollectionViewSource.SortDescriptions>
        <compMod:SortDescription PropertyName="Age" Direction="Ascending"/>
      </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>
  </UserControl.Resources>

  <Grid x:Name="LayoutRoot" Background="White">
    <sdk:DataGrid ItemsSource="{Binding Source={StaticResource dataSource}}" />
  </Grid>

</UserControl>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.