views:

35

answers:

4

This is my ComboBox:

            <ComboBox Name="ApplicationList" MinWidth="200" Margin="4" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding ApplicationName}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

If the combo box contains just strings I get type-down support for free. But how do I enable type-down support for complex objects?

A: 

A workaround is to override the ToString method on the model, but I am looking for a more general solution.

Jonathan Allen
+2  A: 
bufferz
+4  A: 

Set TextSearch.TextPath to the property name:

<ComboBox Name="ApplicationList" TextSearch.TextPath="ApplicationName" MinWidth="200" Margin="4">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ApplicationName}"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

From the documentation:

Use this property on a control that contains a collection of items. The value of the specified property is the text that the user can type to select the item, and the text that is displayed if the control is set to display text in its TextBox.

EDIT: Setting IsEditable to True isn't necessary.

Quartermeister
While people gave me lots of interesting ideas, yours is the only one that didn't require messing around with the object model.
Jonathan Allen
+2  A: 

There are two ways to get this working again. If you're doing something that's actually as simple as your example you can just set

DisplayMemberPath="ApplicationName"

instead of specifying an ItemTemplate.

If you need more options for formatting your items that require using an ItemTemplate set TextSearch.TextPath to the property that you want to do text selection on:

TextSearch.TextPath="ApplicationName"
John Bowen