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

DelegateFilterDescriptor

To use a DelegateFilterDescriptor, you need to create a class that implements the IFilter interface which will return the key you want to filter by. Then, you can add a DelegateFilterDescriptor to the FilterDescriptors collection of the DataGrid and set its Filter property.

Adding a DelegateFilterDescriptor

The following examples demonstrate how to populate the DataGrid with sample data and add a DelegateFilterDescriptor.

Add the DataGrid in XAML

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid" 
      xmlns:dataCore="using:Telerik.Data.Core"> 
    <grid:RadDataGrid x:Name="grid" Width="300" VerticalAlignment="Center"> 
        <grid:RadDataGrid.FilterDescriptors> 
            <dataCore:DelegateFilterDescriptor> 
                <dataCore:DelegateFilterDescriptor.Filter> 
                    <local:CustomFilter/> 
                </dataCore:DelegateFilterDescriptor.Filter> 
            </dataCore:DelegateFilterDescriptor> 
        </grid:RadDataGrid.FilterDescriptors> 
    </grid:RadDataGrid> 
</Grid> 
The IFilter interface contains the PassesFilter method, which receives an instance of the custom object. The value that is returned determines whether the object is filtered. In that case, the filtering is done by the number of letters in each country.

Populate the DataGrid with Data

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
        this.InitializeComponent(); 
 
        List<CustomData> data = new List<CustomData> 
        { 
            new CustomData { Country = "Brazil", City = "Caxias do Sul" }, 
            new CustomData { Country = "Brazil", City = "Fortaleza" }, 
            new CustomData { Country = "Spain", City = "Malaga" }, 
            new CustomData { Country = "Bulgaria", City = "Koynare" }, 
            new CustomData { Country = "Spain", City = "Valencia" }, 
            new CustomData { Country = "Ghana", City = "Kade" }, 
            new CustomData { Country = "Brazil", City = "Porto Alegre" }, 
            new CustomData { Country = "Bulgaria", City = "Byala Slatina" }, 
            new CustomData { Country = "Brazil", City = "Joinville" }, 
        }; 
        this.grid.ItemsSource = data; 
    } 
} 
 
public class CustomData 
{ 
    public string City { get; set; } 
    public string Country { get; set; } 
} 
 
public class CustomFilter : IFilter 
{ 
    public bool PassesFilter(object item) 
    { 
        if ((item as CustomData).Country.Length < 6) 
        { 
            return true; 
        } 
        else 
        { 
            return false; 
        } 
    } 
} 
Result after Filtering

WinUI Delegate Filter Descriptor Example

See Also

In this article
Not finding the help you need?