Autocomplete for ComboBox in WPF anywhere in text (not just beginning)


Question

I've got a ComboBox in WPF that I've mucked around with quite a lot (it has a custom template and a custom item template). I've got it to the point now where it is working pretty much how I want it, except that when I type into the ComboBox it is doing the filtering for me, but only filters assuming what I type starts the name of the item in the ComboBox.

For example if I have an item in the ComboBox called "Windows Media Player" it will only find it if I start typing "Windows Media..." and it won't find it if I start typing "Media Play...". Is there any way around this? Can I set a property somewhere to tell it to search in the whole string rather than just using StartsWith()?

If not, what would be the best way to go about making it do this by myself? Is there some way to take the original control and basically just change the call to StartsWith() to a call to Contains(), or would I have to go far more low-level?

1
29
2/6/2009 10:34:13 PM

Accepted Answer

Check out the following article in CodeProject: A Reusable WPF Autocomplete TextBox

8
12/30/2009 8:25:10 PM

The combobox now supports autocomplete, just make sure in the xaml for the combobox put

IsEditable="True"

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon