开发者_Python百科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?
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.
精彩评论