How to show dropdown menu in combo box in WPF?

When the user starts typing in the combo box, it is automatically populated and shows the closest match. I want the popup to be visible as if the user had clicked the down arrow. Can this be done, and if so, how?

+3
source share
2 answers

You can associate an event KeyDownwith ComboBox, and then set the IsDropDownOpenvalue of the property .

in XAML:

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

in the code behind:

private void MyComboBox_KeyDown(object sender, KeyEventArgs e) {
    if (MyComboBox.Text.Length > 0)
        MyComboBox.IsDropDownOpen = true;
}
+2
source
ComboBox comboBox = new ComboBox;
comboBox.DroppedDown = true;
0
source

Source: https://habr.com/ru/post/1739191/


All Articles