New to Telerik UI for WinUI? Download free 30-day trial


The difference between DelegateSortDescriptor and PropertySortDescriptor is that DelegateSortDescriptor sorts data by a custom кey, while the PropertySortDescriptor sorts by a defined key, which is a property from our model.

Adding a DelegateSortDescriptor

To use a DelegateSortDescriptor, you need to create a class that implements the IKeyLookup interface which will return the кey you want to sort by. Then you need to add the DelegateSortDescriptor to the SortDescriptors collection and set its KeyLookUp property as demonstrated in Example 1.

Example 1: Defining the RadDataGrid in xaml

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid" 
    <grid:RadDataGrid Width="600" Height="460" x:Name="grid" > 
            <dataCore:DelegateSortDescriptor SortOrder="Ascending"> 

The RadDataGrid is populated with data in the same manner as in Example 2 from the PropertySortDescriptor article.

Example 2 demonstrates the implementation of the IKeyLookup interface. The GetKey method will receive an instance of our custom object. In this case the key we return is the number of letters in each city.

Example 2: Defining the CustomIKeyLookup class

public class CustomIKeyLookup : IKeyLookup 
    public object GetKey(object instance) 
        return (instance as CustomData).City.Length; 

Figure 1: Sorted RadDataGrid

Delegate Sort Descriptor

See Also

In this article
Not finding the help you need?