如何通过键入在 WPF 列表框中查找项目?

发布于 2024-07-22 01:49:00 字数 262 浏览 3 评论 0原文

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

我需要在 WPF ListBox 中执行此操作。 但是,这些项目不是纯字符串 - 它们是我使用 DataTemplate 呈现的自定义对象。 我希望有一种方法可以提供字符串值的路径,该路径应用于 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.

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.

How is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不回头走下去 2024-07-29 01:49:00

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

例如

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

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

e.g.

<ListBox IsTextSearchEnabled="True" 
         TextSearch.TextPath="CustomObject.StringProperty"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文