WPF: Button single click + double click issue

后端 未结 2 1422
傲寒
傲寒 2020-11-29 12:13

I have to handle both the single click and the double click of a button in a WPF application with different reaction. Unfortunately, on a doubleclick, WPF fires two click ev

2条回答
  •  星月不相逢
    2020-11-29 12:34

    You could try this:

    Button.MouseLeftButtonDown += Button_MouseLeftButtonDown;
    
    private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        e.Handled = true;
    
        if (e.ClickCount > 1)
        {
            // Do double-click code
        }
    
        else
        {
            // Do single-click code
        }
    }
    

    If neccessary, you could require mouse click and wait until mouse up to perform the action.

提交回复
热议问题