views:

490

answers:

2

What is the best way to implement an auto-suggest feature for a textbox in WPF? I have found various article that are convoluted (and old) and some also suggest that there is a control available for this (but its not in my current WPF toolkit). What's the latest/best method for implementing auto-suggest as a user is typing in to a textbox?

+2  A: 

You can find some nice implementation of 'AutoCompleteTextBox' here and here

Jobi Joy
Thank you. The first article you listed (at http://www.codeproject.com/KB/WPF/WPFAutoCompleteTextbox.aspx) was the best one and easiest one to implement
Jim Beam
+1  A: 

First approach is to use ComboBox because it already have such functionality. You can use TextSearch feature of it. To enable this feature use this code (sorry, it is quick and dirty):

<ComboBox ItemsSource="{Binding AutoSuggestionVariants}">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="{x:Type ComboBoxItem}">
            <Setter Property="TextSearch.Text" Value="{Binding}" />
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>

Also if you need it, you can restyle combo box such that it will look like a text box (remove button and popup list).

Another approach is to use CollectionView. This article describes how to do about the same feature as TextSearch for combo box. I think you can adopt this idea to text box.

Hope it helps.

levanovd