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 中找到项目?
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 将数据集转换为列表 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
