Editable ComboBox with binding to value not in list
I was just doing this yesterday and today and it looks like the following:
set the combobox
IsEditable="true"
instead of binding to
SelectedItem
, bind to theText
property of the comboboxif you're binding to a custom object instead of just strings, you need to also set
TextSearch.TextPath="NameOfField"
. This lets the text search behavior work, and also shows this property in the textbox as well.
All in all, I ended up with something like:
<ComboBox x:Name="c" IsEditable="True" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" StaysOpenOnEdit="True" Text="{Binding NameOnViewModel}" TextSearch.TextPath="NameOnChildItems" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource DataTemplate}" /><TextBlock Text="{Binding ElementName=c,Path=Text}" />