• Stars
    star
    101
  • Rank 337,013 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An attached behavior for WPF's TextBox control that provides auto-completion suggestions from a given collection

WPFTextBoxAutoComplete

An attached behavior for WPF's TextBox control that provides auto-completion suggestions from a given collection

How to use this library:

  1. Install the package via NuGet

    	PM> Install-Package WPFTextBoxAutoComplete
    
  2. Add a reference to the library in your view

    	xmlns:behaviors="clr-namespace:WPFTextBoxAutoComplete;assembly=WPFTextBoxAutoComplete"
  3. 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}" 
    	/>
  4. (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"
    	/>
  5. (Optional) Set the "AutoCompleteIndicator" property, which is a String. This is used to indicate to the behavior that it should start making auto-completion suggestions.

    	<TextBox 
    		Width="250"
    		HorizontalAlignment="Center"
    		Text="{Binding TestText, UpdateSourceTrigger=PropertyChanged}" 
    		behaviors:AutoCompleteBehavior.AutoCompleteItemsSource="{Binding TestItems}" 
    		behaviors:AutoCompleteBehavior.AutoCompleteIndicator="@"
    	/>

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".