开发者

How do I show the drop-down in a combobox in WPF?

开发者 https://www.devze.com 2022-12-25 07:32 出处:网络
When the user starts typing in a combobox, 开发者_JS百科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 do

When the user starts typing in a combobox, 开发者_JS百科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?


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

in XAML:

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

in code behind:

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


ComboBox comboBox = new ComboBox;
comboBox.DroppedDown = true;
0

精彩评论

暂无评论...
验证码 换一张
取 消