WPF IsEditable=true ComboBox filled with objects displays the ToString() as the selected item

You can do this entirely within Xaml

<ComboBox IsTextSearchEnabled="True" IsEditable="True"
        ItemsSource="{Binding MyObjectCollection}"
        TextSearch.TextPath="MyObjectName">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding MyObjectName}" />
        </DataTemplate>
     </ComboBox.ItemTemplate>
</ComboBox>

The upside is that you can define and change this however you want in your XAML without any code-behind. You bind the ItemsSource to your collection of objects, and then you set the path on which to base your search to TextSearch.TextPath. Then, within you custom ItemTemplate you can bind the TextBlock to something else outside of the object’s ToString method.

Leave a Comment