CollectionViewSource.SortDescriptions Property
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)
<collectionViewSource> <collectionViewSource.SortDescriptions> oneOrMoreSortDescriptions </collectionViewSource.SortDescriptions> </collectionViewSource>
XAML Values
Term | Definition |
oneOrMoreSortDescriptions | One or more SortDescription elements. |
Property Value
Type: System.ComponentModel.SortDescriptionCollectionA collection of SortDescription objects that describe how the items in the collection are sorted in the view.
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="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:DesignDataDemo" xmlns:compMod="clr-namespace:System.ComponentModel;assembly=System.Windows" xmlns:sdk="http://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>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.