Telerik UI for Windows Phone by Progress

Besides using a collection of strings as a source for filtered suggestions, RadAutoCompleteBox supports displaying more complex suggestion templates that visualize multiple properties of a custom business object. RadAutoCompleteBox exposes the FilterKeyProvider and FilterKeyPath properties which are used in this context.

Using the FilterKeyPath property

The FilterKeyPath property gets or sets a string that represents the name of the property on a single business object from the suggestions source collection that will be used to filter the object according to the current user input in RadAutoCompleteBox.

A simple scenario that demonstrates the usage of this property is shown below.

Suppose we have the following C# class:

CopyC#
public class Street
{
    public string Name
    {
        get;
        set;
    }

    public string State
    {
        get;
        set;
    }

    public string Country
    {
        get;
        set;
    }

    public string City
    {
        get;
        set;
    }
}

and we use instances of it to bind the SuggestionsSource property of RadAutoCompleteBox. Now we choose the property which value we would like to use when filtering suggestions based on user input in the following way:

CopyXAML
<telerikInput:RadAutoCompleteBox x:Name="radAutoCompleteBox" FilterKeyPath="Name"/>

Here, as the end user types, all Street instances will be filtered based on the user input and the value which is returned by the Name property defined by the Street class.

Using the FilterKeyProvider property

The FilterKeyProvider gets or sets a delegate which is called for each object from the SuggestionsSource collection to provide the key which will be used when deciding whether the object is a valid suggestion according to the current user input. This property cannot be set in XAML and provides a possibility for more complex filter keys, i.e. filter keys composed from a couple of properties on the source object.

The following code snippet demonstrates how a custom filter key provider for the Name property of the Street class mentioned above is defined:

CopyC#
this.radAutoCompleteBox.FilterKeyProvider = (object item) =>
{
    return (item as Street).Name;
};

See Also