AutoComplete TextBox in WPF

后端 未结 8 1448
忘了有多久
忘了有多久 2020-11-27 11:17

Is it possible to make a textbox autocomplete in WPF?

I found a sample where a combo box is used and the triangle is removed by editing the style template.

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 11:39

    Nimgoble's is the version I used in 2015. Thought I'd put it here as this question was top of the list in google for "wpf autocomplete textbox"

    1. Install nuget package for project in Visual Studio

    2. Add a reference to the library in the xaml:
      xmlns:behaviors="clr-namespace:WPFTextBoxAutoComplete;assembly=WPFTextBoxAutoComplete"

    3. Create a textbox and bind the AutoCompleteBehaviour to List (TestItems):
      behaviors:AutoCompleteBehavior.AutoCompleteItemsSource="{Binding TestItems}" />

    IMHO this is much easier to get started and manage than the other options listed above.

提交回复
热议问题