自动完成的组合框在WPF中的任何地方文本(而不是刚刚开始)组合、自动完成、而不是、文本

2023-09-04 22:45:12 作者:Golven [流浪]

我有在WPF组合框,我已经有相当多的(它有一个自定义模板,自定义项目模板)搞乱身边。我已经得到它的地步,现在它正在pretty的多,我怎么想的那样,只是当我键入它做过滤,我的组合框,但只过滤假设我键入开头的名称在组合框中的项目。

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.

例如,如果我有所谓的Windows媒体播放器组合框中的项目,只会觉得如果我开始打字Windows媒体...也不会找到它,如果我开始打字媒体播放。 ..。有没有解决这个办法吗?我可以在某处设置一个属性来告诉它在整个字符串进行搜索,而不是仅仅使用StartsWith()?

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()?

如果没有,这将是着手做它用自己做到这一点的最好方法是什么?是否有某种方式把原有的控制基本上只是调用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?

推荐答案

检查在$ C $的CProject下面的文章: 可复用WPF自动完成文本框

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