ComboBox with filtering (auto-complete) for WPF
Provides a lightweight combobox with filtering (auto-complete).
Declare XML namespace.
<Window
...
xmlns:dotNetKitControls="clr-namespace:DotNetKit.Windows.Controls;assembly=DotNetKit.Wpf.AutoCompleteComboBox"
... >
Then you can use AutoCompleteComboBox
. It's like a normal ComboBox
because of inheritance.
<dotNetKitControls:AutoCompleteComboBox
SelectedValuePath="Id"
TextSearch.TextPath="Name"
ItemsSource="{Binding Items}"
SelectedItem="{Binding SelectedItem}"
SelectedValue="{Binding SelectedValue}"
/>
Note that:
TextSearch.TextPath
property.
Person
, which has Name
property, and the property path is "Name". If the user input "va", the combobox filters the items to remove ones (persons) whose Name
don't contain "va".TextSeach.Text
.ComboBox.Items
property directly. Use ItemsSource
instead.DisplayMemberPath
.This library works fine in the default setting, however, it also provides how to configure.
AutoCompleteComboBox.Setting
property.<dotNetKitControls:AutoCompleteComboBox
Setting="..."
...
/>
AutoCompleteComboBoxSetting.Default
to apply to all comboboxes.Filtering allows you to add a lot of items to a combobox without loss of usability, however, that makes the performance poor. To get rid of the issue, we recommend you to use VirtualizingStackPanel
as the panel.
Use ItemsPanel
property:
<dotNetKitControls:AutoCompleteComboBox ...>
<dotNetKitControls:AutoCompleteComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</dotNetKitControls:AutoCompleteComboBox.ItemsPanel>
</dotNetKitControls:AutoCompleteComboBox>
or declare a style in resources as the Demo app does.
See also WPF: Using a VirtualizingStackPanel to Improve ComboBox Performance for more detailed explanation.