如何通过键入在 WPF ListBox 中找到项目? [英] How can I find an item in a WPF ListBox by typing?

查看:26
本文介绍了如何通过键入在 WPF ListBox 中找到项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数列表框允许您通过键入显示文本的首字母来查找其中的项目.如果键入的字母匹配多个项目,则可以继续添加字母以缩小搜索范围.

Most list boxes allow you to find items within them by typing the first letters of the displayed text. If the typed letters match multiple items, then you can keep adding letters to narrow the search.

我需要在 WPF ListBox 中执行此操作.但是,这些项目不是纯字符串——它们是我使用 DataTemplate 呈现的自定义对象.我希望有一种方法可以提供字符串值的路径,该路径应该用于 ListBox 项的文本键盘导航.

I need to do this in a WPF ListBox. However, the items aren't plain strings -- they're custom objects that I present using a DataTemplate. I'm hoping that there's a way I can provide a path to the string value that should be used for this textual keyboard navigation of the ListBox items.

这怎么可能?

推荐答案

您可以尝试将 IsTextSearchEnabled 设置为 true 并使用 TextSearch.TextPath 附加属性.

You could try setting IsTextSearchEnabled to true and using the TextSearch.TextPath attached property.

例如

<ListBox IsTextSearchEnabled="True" 
         TextSearch.TextPath="CustomObject.StringProperty"/>

这篇关于如何通过键入在 WPF ListBox 中找到项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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