An attached behavior for WPF's TextBox control that provides auto-completion suggestions from a given collection
-
Install the package via NuGet
PM> Install-Package WPFTextBoxAutoComplete
-
Add a reference to the library in your view
xmlns:behaviors="clr-namespace:WPFTextBoxAutoComplete;assembly=WPFTextBoxAutoComplete"
-
Create a textbox and bind the "AutoCompleteItemsSource" to a collection of
IEnumerable<String>
<TextBox Width="250" HorizontalAlignment="Center" Text="{Binding TestText, UpdateSourceTrigger=PropertyChanged}" behaviors:AutoCompleteBehavior.AutoCompleteItemsSource="{Binding TestItems}" />
-
(Optional) Set the "AutoCompleteStringComparison" property, which is of type StringComparison
<TextBox Width="250" HorizontalAlignment="Center" Text="{Binding TestText, UpdateSourceTrigger=PropertyChanged}" behaviors:AutoCompleteBehavior.AutoCompleteItemsSource="{Binding TestItems}" behaviors:AutoCompleteBehavior.AutoCompleteStringComparison="InvariantCultureIgnoreCase" />
Now, every time the "TestText" property of your datacontext is changed, WPFTextBoxAutoComplete will provide you with auto-completion suggestions. To accept a suggestion, just hit "enter".