In this tip, I'll try to explain how to use my
AutoCompleteTextBox for WPF. The
AutoCompleteTextBox is similar to
TextBox with auto complete behavior. You can provide user suggestions while he/she is typing in the text box.
AutoCompleteTextBox works asynchronously to find and display suggestions, so user doesn't have to wait for suggestions on every key-stroke.
I really missed the auto complete feature of
TextBox in WPF. I decided to create my own
TextBox control with auto complete behavior. My objective was not to keep it just limited to the filtering from a list of
strings. I have tried to keep the control as simple as possible, yet fully featured and it completely supports MVVM design pattern. You can download the latest source code from https://wpfautocomplete.codeplex.com/.
- Load suggestions on-demand
- Supports MVVM
- Asynchronously load suggestions
DataTemplate for suggestions
DataTemplateSelector for suggestions
How Does It Work?
AutoCompleteTextBox is mainly divided in three parts,
[TemplatePart(Name = AutoCompleteTextBox.PartEditor, Type = typeof(TextBox))]
[TemplatePart(Name = AutoCompleteTextBox.PartPopup, Type = typeof(Popup))]
[TemplatePart(Name = AutoCompleteTextBox.PartSelector, Type = typeof(Selector))]
public class AutoCompleteTextBox : Control
public const string PartEditor = "PART_Editor";
public const string PartPopup = "PART_Popup";
public const string PartSelector = "PART_Selector";
|Editing area where user can type any text to search
|A dropdown that contains the suggestions
|Display each item in the suggestions
ISuggestionProvider to get a list of suggestions to display. When user types in any text in the
textbox, it calls the
ISuggestionProvider.GetSuggestions method, which is supposed to return an
IEnumerable type. You can define a delay period by
Delay property, for which
AutoCompleteTextBox must wait for another key-stroke before making a call to
public interface ISuggestionProvider
IEnumerable GetSuggestions(string filter);
Using the Control
To add the
AutoCompleteTextBox in your view, you need to import
http://wpfcontrols.com/ namespace in the XAML.
As I mentioned earlier that
ISuggestionProvider to get a list of suggestions, we need to create a provider which will return our suggestions. The below code example shows how to create a suggestion provider.
var provider = new SuggestionProvider(x =>
Please visit CodePlex for version history and for downloading the latest version of the