We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to filter using Custom SuggestionMode in AutoComplete?

Platform: WPF |
Control: SfTextBoxExt |
Published Date: November 17, 2014 |
Last Revised Date: June 21, 2019

You can filter by single letter suggestion using Custom SuggestionMode in SfTextBoxExt control.

Create a Custom filter

Create a delegate method matching the predicate <string, T> for filtering suggestions.

Set SuggestionMode and Filter property

Set the property SuggestionMode=”Custom” and the delegate method for Filter property.

XAML

<Window x:Class="AutoComplete_132047.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:input="http://schemas.syncfusion.com/wpf"
        xmlns:local="clr-namespace:AutoComplete_132047"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.DataContext>
            <local:ViewModel/>
        </Grid.DataContext>
        <input:SfTextBoxExt AutoCompleteSource="{Binding Items}" SearchItemPath="Name" AutoCompleteMode="Suggest" SuggestionMode="Custom" x:Name="autoComplete"/>
    </Grid>
</Window>

 

C#

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            autoComplete.Filter = Filter;    
        }
        private bool Filter(string text, object item)
        {
            if ((item as Model).Name.Contains(text))
                return true;
            else
                return false;
        }
    }
public class Model
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
            }
    public class ViewModel
    {
        private List<Model> items;
        public List<Model> Items
        {
            get { return items; }
            set { items = value; }
        }
        public ViewModel()
        {
            items = new List<Model>();
            items.Add(new Model() { Name="A" });
            items.Add(new Model() { Name = "AA" });
            items.Add(new Model() { Name = "AB" });
            items.Add(new Model() { Name = "AC" });
            items.Add(new Model() { Name = "A1" });
            items.Add(new Model() { Name = "B" });
            items.Add(new Model() { Name = "C" });
            items.Add(new Model() { Name = "D" });
            items.Add(new Model() { Name = "E" });
        }
    }

The above code filters using single letter suggestions and the screenshot is as follows.

 

AutoComplete

Figure 1: AutoComplete using Filter

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon