[英]WPF combobox not showing suggestion like winform combobox
I am struggling with WPF Combobox in order to show suggestion while user is typing like this (in WinForms): 我在WPF Combobox方面苦苦挣扎,以便在用户键入以下内容时显示建议(在WinForms中):
But what is happing is that the combobox is appending when user is typing like this (in WPF): 但是,令人困惑的是,当用户键入以下内容时(在WPF中),组合框将追加:
Problem How can I show a dropdown list when user is typing as suggestions 问题当用户输入建议时如何显示下拉列表
Many many thanks for your attention. 非常感谢您的关注。
My Code: 我的代码:
<ComboBox x:Name="item_category" Width="190" IsEditable="True" SelectionChanged="category_SelectionChanged"/>
You should use AutoCompleteBox
which behaves dropdown as well as autocomplete. 您应该使用表现出下拉菜单以及自动完成功能的AutoCompleteBox
。
Add this event to your ComboBox
: 将此事件添加到您的ComboBox
:
<ComboBox Name="cmb1" IsEditable="True" PreviewTextInput="cmb1_PreviewTextInput">
</ComboBox>
Then in the code behind: 然后在后面的代码中:
List<string> db;
public Window()
{
InitializeComponent();
db = new List<string> { "abc","abg","hjn" };
cmb1.ItemsSource = db;
}
private void cmb1_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
cmb1.ItemsSource = db.Where(p => p.Contains(e.Text)).ToList();
cmb1.IsDropDownOpen = true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.