具有自动完成/自动过滤功能的 WPF 组合框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3831731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:10:19  来源:igfitidea点击:

WPF Combobox with auto-complete/auto-filter?

wpf.net-3.5comboboxautocomplete

提问by ewall

I am eager to find some solid (free, Open Source, or tutorial/example) code to make a WPF Combobox do autocomlete/autofilter as the user types. But everything I've tried so far has had some sort of problem...

我渴望找到一些可靠的(免费的、开源的或教程/示例)代码来使 WPF 组合框在用户键入时执行自动完成/自动过滤。但是到目前为止我尝试过的一切都有一些问题......

Other things I've considered:

我考虑过的其他事情:

  • I know that Windows Forms' Combobox control has AutoCompleteModeand I could embed it in WPF, but I can't imagine it would play very well with my WPF data bindings.

  • Perhaps it is too complex and I need to simplify, maybe by building one-dimensional (single-property) ObservableCollections for the ComboBoxen... However, the challenge of applying multiple filters (one set by another control's value, and one from what the user is typing) to multiple controls using different views of the same DataSet would require a ridiculous amount of processing power to destroy and rebuild the list every time the user types a character!

  • 我知道Windows 窗体的 Combobox 控件具有 AutoCompleteMode并且我可以将它嵌入 WPF 中,但我无法想象它会与我的 WPF 数据绑定配合得很好。

  • 也许它太复杂了,我需要简化,也许通过为 ComboBoxen 构建一维(单一属性)ObservableCollections ......但是,应用多个过滤器的挑战(一个由另一个控件的值设置,一个来自哪个控件的值)用户正在键入)到使用同一数据集的不同视图的多个控件,每次用户键入一个字符时,都需要大量的处理能力来破坏和重建列表!

So... I'm at wit's end. Any suggestions?

所以......我在智慧的尽头。有什么建议?

回答by TalentTuner

If your Combobox has some data source attached to it , just make

如果您的组合框附加了一些数据源,只需制作

1-IsTextSearchEnabled = true.
2-IsEditable = true.

you are good to go

你已准备好出发