WPF 中 ComboBox 的自动完成文本中的任何位置(不仅仅是开始) [英] Autocomplete for ComboBox in WPF anywhere in text (not just beginning)

查看:14
本文介绍了WPF 中 ComboBox 的自动完成文本中的任何位置(不仅仅是开始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WPF 中有一个 ComboBox,我对它进行了很多处理(它有一个自定义模板和一个自定义项目模板).我现在已经到了它几乎按照我想要的方式工作的地步,除了当我输入 ComboBox 时它正在为我进行过滤,但仅过滤器假设我输入的内容开始项目的名称组合框.

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.

例如,如果我在 ComboBox 中有一个名为Windows Media Player"的项目,它只会在我开始输入Windows Media..."时找到它,而如果我开始输入Media Play...".有没有办法解决?我可以在某处设置一个属性来告诉它在整个字符串中搜索而不是只使用 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() 的调用更改为 Contains() 的调用,还是我必须走低得多的级别?

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?

推荐答案

在 CodeProject 中查看以下文章:一个可重用的 WPF 自动完成文本框

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

这篇关于WPF 中 ComboBox 的自动完成文本中的任何位置(不仅仅是开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆