如何在 WPF 的组合框中显示下拉菜单? [英] How do I show the drop-down in a combobox in WPF?

查看:34
本文介绍了如何在 WPF 的组合框中显示下拉菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户开始在组合框中输入时,自动完成开始并显示最接近的匹配项.我想要做的是让下拉菜单也变得可见,就好像用户单击了向下箭头一样.可以这样做吗?如果可以,怎么做?

When the user starts typing in a combobox, auto-complete kicks in and shows the closest match. What I want to do is have the drop-down become visible as well, as if the user clicked the down arrow. Can this be done and if yes, how?

推荐答案

您可以在 ComboBox 上钩住 KeyDown 事件,然后设置 IsDropDownOpen 属性为 true.

You could hook the KeyDown event on the ComboBox, and then set the IsDropDownOpen property to true.

在 XAML 中:

<ComboBox x:Name="MyComboBox"
          IsEditable="True"
          IsReadOnly="False"
          KeyDown="MyComboBox_KeyDown"/>

在代码后面:

private void MyComboBox_KeyDown(object sender, KeyEventArgs e) {
    if (MyComboBox.Text.Length > 0)
        MyComboBox.IsDropDownOpen = true;
}

这篇关于如何在 WPF 的组合框中显示下拉菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆