How to filter using Custom SuggestionMode in AutoComplete?
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.

Figure 1: AutoComplete using Filter