Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find an item in a WPF ListBox by typing?

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?

like image 447
Drew Noakes Avatar asked May 28 '09 09:05

Drew Noakes


1 Answers

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

e.g.

<ListBox IsTextSearchEnabled="True" 
         TextSearch.TextPath="CustomObject.StringProperty"/>
like image 62
Jules Avatar answered Oct 24 '22 04:10

Jules