The Problem: I cannot enter custom text to the ComboBox and press Enter to close the dropdown list, because my written custom-text is overwritten by the selected item from the dropdown list.
I use an editable=true and isTextSearchEnabled=true ComboBox with a list of strings:
<ComboBox
IsEditable="True"
IsTextSearchEnabled="True"
ItemsSource="{Binding Names}"
SelectedItem="{Binding SelectedName}"
Text="{Binding Name}"
>
<ComboBox.Style>
<Style>
<EventSetter Event="TextBoxBase.TextChanged"
Handler="cmbTextField_TextChanged" />
</Style>
</ComboBox.Style>
</ComboBox>
TextChanged: Opens the combobox dropdown list if the text is changed
private void cmbTextField_TextChanged(object sender, TextChangedEventArgs e)
{
var cmbx = sender as ComboBox;
//Open the dropdwon
cmbx.IsDropDownOpen = true;
}
How-to get the problem:
- Enter the first letter e.g.: "A". -> it opens the dropdown list and selects the first Name which starts with A.
- Type some additional letters to the end of the found name (to get a new string which is not in the list)
- Press Enter -> dropdown window is closed and my custom text is overwritten with the selected text from the list.
(But it is working correctly if I press TAB instead of Enter) Does anyone know how to solve this issue?
- Update: The problem seems to be related to the IsTextSearchEnabled=true property.