Share via


SortDescriptor.PropertyPath Property

[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.]

Gets or sets the public property used to sort.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.DomainServices (in System.Windows.Controls.DomainServices.dll)

Syntax

'Declaration
Public Property PropertyPath As String
    Get
    Set
'Usage
Dim instance As SortDescriptor
Dim value As String

value = instance.PropertyPath

instance.PropertyPath = value
public string PropertyPath { get; set; }
public:
property String^ PropertyPath {
    String^ get ();
    void set (String^ value);
}
member PropertyPath : string with get, set
function get PropertyPath () : String
function set PropertyPath (value : String)

Property Value

Type: System.String
The public property used to sort.

Remarks

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>

Examples

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>

See Also

Reference

SortDescriptor Class

System.Windows.Controls Namespace