How can I find an item in a WPF ListBox by typing?(如何通过键入在 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 中找到项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过键入在 WPF ListBox 中找到项目?


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01