To clarify, I have a combobox with an observable collection associated with the itemsource property. I want the user to be able to enter only those elements that are present in the collection. keeping
IsTextSearchEnabled="true"
Functionality. So I was looking online for an example of how to do this. So far, I decided that I should use
<ComboBox TextInput="cbb1_TextInput" />
Event, then search the collection. But my weak attempt cannot save the autocomplete function, selectedindex becomes messy and other undesirable behavior. Since I'm pretty busy with wpf, I wonder if there are solutions that use only part of XAML?
EDIT: I tried something like this:
private void fase1cbb1_KeyUp(object sender, KeyEventArgs e) { ComboBox cb = (ComboBox)sender; bool match = false; TextBox tb = (TextBox)cb.Template.FindName("PART_EditableTextBox", cb); if (tb.Text.Length > 0) { foreach (MenuItem MI in cb.Items) { if (MI.Text.StartsWith(tb.Text)) { match = true; ; } } if (!match) { int len = tb.Text.Length; if (len > 0) { tb.Text = tb.Text.Substring(0, len - 1); tb.SelectionStart = len; } } } }
But as soon as there is no match, there is no longer the selected item, and there is no more autocomplete / texts.
thnx for any tips or examples.
SOLUTION: WPF ComboBox with IsEditable = "True" - How can I indicate that no matches were found?
source share