Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 657
robintw Avatar asked Feb 06 '09 22:02

robintw


2 Answers

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

IsEditable="True" 
like image 198
rreeves Avatar answered Oct 05 '22 08:10

rreeves


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

like image 42
Aviad P. Avatar answered Oct 05 '22 07:10

Aviad P.