Y'know how in plain-old Windows ListBox controls, you can type the first few letters of an item, and it'll move the selection to that item for you?

In Windows Presentation Foundation, you lose that behaviour if you assign an ItemTemplate to the ListBox. Because you're no longer just displaying a simple line of text, the ListBox can't know which item you're trying to select when you start typing.

However, I've just discovered a little trick to get that behaviour back when you have an ItemTemplate set. All you have to do is set the DisplayMemberPath property on the ListBox to point to the (text-based) property of the source item that you want to use to look it up.

So let's say you have a list of items with a "Name" property. You can do this:

<ListBox DisplayMemberPath="Name" ItemsSource="{Binding Source={StaticResource MyItemCollection}}" ItemTemplate="{StaticResource MyItemTemplate}"/>

... and now you'll be able to type the first few letters of an item's Name to jump straight to it!

The only caveat is that Visual Studio shows a whole bunch of silent exceptions that it's swallowing in the background, with this message:

System.Windows.Data Error: 20 : Both 'ContentTemplate' and 'ContentTemplateSelector' are set;  'ContentTemplateSelector' will be ignored.

It looks harmless, but it concerns me that this is happening. Still - it's worth it for that keyboard lookup!