我如何可以通过键入找到一个WPF ListBox中的项目? [英] How can I find an item in a WPF ListBox by typing?

查看:244
本文介绍了我如何可以通过键入找到一个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 列表框。然而,项目不是简单的字符串 - 他们是我使用present一个的DataTemplate 自定义对象。我希望有一种方法,我可以提供一个路径,应该用于该文本键盘的列表框项目导航的字符串值。

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天全站免登陆