WPF 可编辑组合框文本搜索行为
我有一个 ComboBox,在 ItemsSource 上绑定了一个 Entity ObservableCollection。像这样:
Key Desc1 Desc2
C0001 myDesc myDesc
D0001 myDesc myDesc
A0001 myDesc MyDesc
组合框是这样定义的:
<ComboBox
IsEditable=True
DisplayMemberPath="Key"
SelectedValuePath="Key"
ItemsSource="{Binding Path=MyList, Mode=OneWay}" />
现在我遇到这个问题...
如果我在组合框的空可编辑文本框中键入一个字符,则匹配“以”键入的字符“开头”的第一个元素。所以,如果我输入“C”,所选项目是元素“C0001”......我会避免这种情况!
我会采用不同的搜索逻辑,根据输入的全文查找所选项目。这样:
Text Typed SelectedItem
C null
C0 null
C00 null
C000 null
C0001 [C0001, myDesc, myDesc] OK!
可以吗?我该怎么办?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 中的组合一直都是这样。如果您想做这样的事情,最好使用搜索字段和可选择的结果列表。
或者,TextBox 确实支持不同的自动完成建议模式,但我想你也需要一个下拉菜单。(不,它不支持)。此帖子尝试将两者结合起来,非常简洁。
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.