Highlighting Matched Text in WPF Autocomplete (SfTextBoxExt)

Highlight matching characters in a suggestion list to pick an item with more clarity using the TextHighlightMode property. The default value is None. The matching text can be highlighted in the following two ways:

  • First occurrence
  • Multiple occurrence

The text highlight can be indicated by customizing the color of the characters using HighlightedTextColor property.

First occurrence

It highlights the first position of the matching characters in the suggestion list.

<editors:SfTextBoxExt HorizontalAlignment="Center" 
                      VerticalAlignment="Center" 
                      Width="300"
                      Height="40"
                      SearchItemPath="Name"
                      AutoCompleteMode="Suggest"
                      HighlightedTextColor="Red"
                      TextHighlightMode="FirstOccurrence"
                      AutoCompleteSource="{Binding Employees}" />
textBoxExt.TextHighlightMode = OccurrenceMode.FirstOccurrence;

First Occurrance

Multiple occurrence

It highlights the matching character that presents everywhere in the suggestion list for “Contains” case in SuggestionMode.

<editors:SfTextBoxExt HorizontalAlignment="Center" 
                      VerticalAlignment="Center" 
                      Width="300"
                      Height="40"
                      SearchItemPath="Name"
                      AutoCompleteMode="Suggest"
                      SuggestionMode="Contains"
                      HighlightedTextColor="Red"
                      TextHighlightMode="MultipleOccurrence"
                      AutoCompleteSource="{Binding Employees}" />
textBoxExt.TextHighlightMode = OccurrenceMode.MultipleOccurrence;

Multiple Occurrance

NOTE

View sample in GitHub