【发布时间】:2026-01-10 06:15:01
【问题描述】:
我在 wpf 控件中有可编辑的组合框。
<ComboBox Width="200" Name="quickSearchText"
TextBoxBase.TextChanged="searchTextChanged"
IsTextSearchEnabled="False"
StaysOpenOnEdit="True" IsEditable="True">
</ComboBox>
在输入文本后,我正在更改组合框项目(如自动完成的文本框)。
private void searchTextChanged(object sender, TextChangedEventArgs e)
{
string text = quickSearchText.Text; //Get typing text.
List<string> autoList = new List<string>();
autoList.AddRange(suggestions.Where(suggestion => !string.IsNullOrEmpty(text)&& suggestion.StartsWith(text))); //Get possible suggestions.
// Show all, if text is empty.
if (string.IsNullOrEmpty(text) && autoList.Count == 0)
{
autoList.AddRange(suggestions);
}
quickSearchText.ItemsSource = autoList;
quickSearchText.IsDropDownOpen = autoList.Count != 0; //Open if any.
}
如果我从下拉列表中选择一个项目或输入文本并按Enter,TextboxBase 冻结并且我无法编辑它。 (但可以突出显示文本并打开/关闭下拉菜单)
如何解决?
【问题讨论】:
-
您可以使用
TextBox控制和Popup Control with Combobox。在 TextBox 的TextChanged事件中,您可以显示/隐藏Popup。 -
@Amol Bavannavar 谢谢。这是解决方案之一。但是为什么当前的解决方案不起作用?