WPF ComboBox: click outside of popup suppress mouse click

前端 未结 3 1699
[愿得一人]
[愿得一人] 2021-01-21 17:15

I use a standard WPF ComboBox control. When popup is opened and user clicks somewhere outside, popup is closed. But if there is button on the window and user clicks on it (with

3条回答
  •  無奈伤痛
    2021-01-21 17:59

    I used an easy solution: In the PreviewMouseLeftButtonDown event, if the mouse pos is outside the combobox, close the dropdown. This will allow other control to get the mouse click:

    Dim p = Mouse.GetPosition(combo)
    If p.X < 0 OrElse p.Y < 0 OrElse p.X > combo.Width OrElse p.Y > combo.Height Then
         cmb.IsDropDownOpen = False
    End If
    

提交回复
热议问题