views:

1033

answers:

1

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?

+6  A: 

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

e.g.

<ListBox IsTextSearchEnabled="True" 
         TextSearch.TextPath="CustomObject.StringProperty"/>
Jules
Thanks very much. This worked perfectly. Just to be clear, the TextPath value should be a path (the first part looks like a type name, but in this case the item has a property called 'CustomObject' and that object has a property called 'StringProperty'.)
Drew Noakes