Click here to Skip to main content
Click here to Skip to main content

WPF Auto-complete Control

, 14 Dec 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Implementing an auto-complete control in WPF by extending the ComboBox control.


There seems to be a lack of support for an auto-complete control in WPF. The closest one to it is the ComboBox which is the base of our implementation for this article.


An auto-complete control is one that allows the user to enter text while querying for a possible selection based on what the user has already entered. The most popular auto-complete implementation deals with querying of a "Starts With" of the current text in the control.

How it Works

Here are some of the properties we care about in the ComboBox:

  • IsEditable- This allows the user to input text into the control.
  • StaysOpenOnEdit - This will force the combobox to stay open when typing.
  • IsTextSearchEnabled - This uses the default "auto-complete" behavior of the ComboBox.

The Magic

By using a combination of the above properties (pretty self-explanatory) and a timer to control the delay of the query, an event which allows the user to attach a new data source, and some styles, we could implement an auto-complete control.

Using the Control


<Window x:Class="Gui.TestWindow"
      Title="Auto Complete Test" 
      Height="200" Width="300" 
              Source="/Gui.Controls;component/Styles/AutoComplete.Styles.xaml" />
        <ctr:AutoComplete x:Name="autoCities" 
           SelectedValuePath="CityID" DisplayMemberPath="Name" 
           Style="{StaticResource AutoCompleteComboBox}"
        <!-- can also do binding on selected value -->

Similar to a combo box, an auto-complete control utilizes the DisplayMemberPath and SelectValuePath properties to bind to a specific data source.


/// <summary>
/// occurs when the user stops typing after a delayed timespan
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void autoCities_PatternChanged(object sender, 
          Gui.Controls.AutoComplete.AutoCompleteArgs args)
    if (string.IsNullOrEmpty(args.Pattern))
        args.CancelBinding = true;
        args.DataSource = TestWindow.GetCities(args.Pattern);

We can utilize the PatternChanged event to subscribe to changes to the the data source. This data source is also equal to a pattern the user has currently entered into the control.

Points of Interest

We utilize the MVVM pattern to create a ViewModel of any entity bound to the data source which contains the HighLight property. Through the use of styles, this highlighted section will be reflected in the dropdown.


  • Dec. 14, 2009 - Initial creation.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Yang Yu
Canada Canada
Engineer, maker, food lover
Follow on   Twitter   LinkedIn

Comments and Discussions

Questionusing in xceed datagrid control Pinmemberpiyu_nehal15-Apr-13 4:43 
QuestionHow to bind to data PinmemberFrank Cazabon2-Jan-13 6:35 
I'm trying to use this control and bind it to some data.
If it were a combo box I would set it up like this:
<ComboBox Name="cboCustomers" DisplayMemberPath="cus_number" SelectedValuePath="cus_pk" SelectedValue="{Binding inv_cusfk, Mode=Default}" />
If I try this with the autocomplete control I don't get the customer number displaying when viewing existing data:
<ctr:AutoComplete x:Name="autoCustomers" Grid.Row="3" Grid.Column="1" 
                                          SelectedValuePath="cus_pk" DisplayMemberPath="cus_number" 
                                          SelectedValue="{Binding inv_cusfk, Mode=Default}"
                          Delay="500" LostFocus="autoCustomers_LostFocus" />

QuestionPopulate with a value? Pinmembernyland25-Jan-12 11:30 
QuestionConverting to VB Pinmemberchj12424-Jun-11 9:19 
GeneralMy vote of 5 Pinmembernjdnjdnjdnjdnjd9-May-11 23:44 
GeneralMy vote of 1 PinmemberVolcano_881018-Nov-10 18:38 
GeneralGetting ItemsSource to work Pinmembercjroebuck15-Dec-09 7:52 
GeneralRe: Getting ItemsSource to work PinmemberYang Yu15-Dec-09 8:29 
GeneralThanks a lot! PinmemberRatish Philip15-Dec-09 0:46 
GeneralRe: Thanks a lot! PinmemberYang Yu15-Dec-09 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150302.1 | Last Updated 14 Dec 2009
Article Copyright 2009 by Yang Yu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid