WPF - automatically suggest text as a type of person in the control text box

What is the best way to implement an automatic suggestion function for a text field in WPF? I found several articles that were confusing (and old), and some also suggest that there is a control for this (but this is not in my current WPF toolbox). What is the last / best method to implement an automatic suggestion as a user is entering into a text box?

+6
autocomplete wpf
source share
1 answer

The first approach is to use ComboBox, as it already has this functionality. You can use the TextSearch function. To enable this feature, use this code (sorry, it's quick and dirty):

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

In addition, if you need it, you can use the combo box to make it look like a text field (delete button and popup list).

Another approach is to use CollectionView. This article describes how to do the same function as TextSearch for the combo box. I think you can take this idea in a text box.

Hope this helps.

+2
source share

All Articles