Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SortDescriptor Class

WCF RIA Services

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Describes a sorting criterion.

System.Object
  System.Windows.DependencyObject
    System.Windows.Controls.SortDescriptor

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.DomainServices (in System.Windows.Controls.DomainServices.dll)
public class SortDescriptor : DependencyObject

The SortDescriptor type exposes the following members.

  NameDescription
Public methodSortDescriptor()Initializes a new instance of the SortDescriptor class with default property values.
Public methodSortDescriptor(String, ListSortDirection)Initializes a new instance of the SortDescriptor class with the specified property to use for sorting, and the sort direction.
Top
  NameDescription
Public propertyDirectionGets or sets the sort direction.
Public propertyDispatcher (Inherited from DependencyObject.)
Public propertyPropertyPathGets or sets the public property used to sort.
Top
  NameDescription
Public methodCheckAccess (Inherited from DependencyObject.)
Public methodClearValue (Inherited from DependencyObject.)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetAnimationBaseValue (Inherited from DependencyObject.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodGetValue (Inherited from DependencyObject.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodReadLocalValue (Inherited from DependencyObject.)
Public methodSetValue (Inherited from DependencyObject.)
Public methodToString (Inherited from Object.)
Top
  NameDescription
Public fieldStatic memberDirectionPropertyIdentifies the Direction dependency property.
Public fieldStatic memberPropertyPathPropertyIdentifies the PropertyPath dependency property.
Top

The DomainDataSource class provides the SortDescriptors collection to facilitate sorting data. In the SortDescriptors collection, you add SortDescriptor instances that describe the values to use for sorting the collection. You can add as many SortDescriptor instances as you want to provide layers of sorting. You can specify if the data is sorted in ascending or descending order.

If you use SortDescriptor programmatically, verify that the CanLoad property returns true. Attempting to sort when CanLoad returns false, causes the DomainDataSource to throw an invalid operation exception. Sorting initiates a load operation, and load operations are not permitted when CanLoad is false.

The following example shows how to add a sort descriptor to the DomainDataSource. The data retrieved from the query is sorted by values in the StandardCost property.

<Grid x:Name="LayoutRoot" Background="White">  
    <riaControls:DomainDataSource x:Name="source" QueryName="GetProducts" AutoLoad="true">
        <riaControls:DomainDataSource.DomainContext>
            <domain:ProductDomainContext />
        </riaControls:DomainDataSource.DomainContext>   
        <riaControls:DomainDataSource.SortDescriptors>
            <riaData:SortDescriptor PropertyPath="StandardCost" Direction="Ascending" />
            <riaData:SortDescriptor PropertyPath="ProductID" Direction="Ascending" />
        </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>
    <data:DataGrid ItemsSource="{Binding Data, ElementName=source}" />
</Grid>


When you implement paging and sorting together, include at least one SortDescriptor with its PropertyPath attribute assigned to a property that contains unique values, such as a primary key. Or add an OrderBy clause based on a property that contains unique values to the query in the DomainDataSource. If you only sort the data on a property that does not contain unique values, the return values could contain inconsistent or missing data across pages.

For example, consider the values in the following table. Note that the ID values are unique, but the Country values are not unique.

ID

Country

1

UK

2

UK

3

US

4

UK

5

US

6

IT

7

UK

8

UK

9

US

10

SP

If you want to implement paging for these values, sorted by Country, you could use the following markup:

<Grid x:Name="LayoutRoot">
    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
        <StackPanel x:Name="ContentStackPanel">
            <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" 
                               Text="Home"/>
            <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}" 
                               Text="Home page content"/>
            <riaControls:DomainDataSource Name="domainDataSource1" QueryName="GetCountriesQuery" PageSize="4">
                <riaControls:DomainDataSource.DomainContext>
                    <ds:TestDomainContext></ds:TestDomainContext>
                </riaControls:DomainDataSource.DomainContext>
                <riaControls:DomainDataSource.SortDescriptors>
                    <riaControls:SortDescriptor PropertyPath="Country" Direction="Ascending"></riaControls:SortDescriptor>
                    <riaControls:SortDescriptor PropertyPath="ID"></riaControls:SortDescriptor>
                </riaControls:DomainDataSource.SortDescriptors>
            </riaControls:DomainDataSource>
            <my:DataGrid ItemsSource="{Binding Data, ElementName=domainDataSource1}" />
            <my:DataPager PageSize="4" Source="{Binding Data, ElementName=domainDataSource1}" />
        </StackPanel>
    </ScrollViewer>
</Grid>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft. All rights reserved.