简体   繁体   中英

WPF Editable ComboBox Text Search Behavior

I have a ComboBox with binded an Entity ObservableCollection on ItemsSource. Like this:

Key    Desc1   Desc2
C0001  myDesc  myDesc
D0001  myDesc  myDesc
A0001  myDesc  MyDesc

the combobox is so defined:

<ComboBox
   IsEditable=True
   DisplayMemberPath="Key"
   SelectedValuePath="Key"
   ItemsSource="{Binding Path=MyList, Mode=OneWay}" />

Now I have this problem...

If I type a character on empty editable textbox of combobox, the first element that "startswith" the typed character is matched. So, If I type "C", the selecteditem is the element "C0001"...and I would avoid this!

I would a different search logic that find the selecteditem based on full text typed. In this way:

Text Typed        SelectedItem
C                 null
C0                null
C00               null
C000              null
C0001             [C0001, myDesc, myDesc] OK!

Is possible? How can I do?

This behaviour has always been like this for Combos in Windows. If you want to do something like this, you're probably better off with a search field and a pickable list of results.

Alternatively, the TextBox does support different AutoComplete suggestion modes, but you want a dropdown too I'd imagine. (no, it doesn't).

This post makes a stab at coupling the two up, it's pretty neat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM