WPF button 如何區分click和doubleclick

WPF button 同時處理兩個事件時候會先觸發click事件,觸發doubleclick事件  ,那如何區分呢,能夠這樣設置:spa

  private static DispatcherTimer myClickWaitTimer =
            new DispatcherTimer(
                new TimeSpan(0, 0, 0, 1),
                DispatcherPriority.Background,
                mouseWaitTimer_Tick,
                Dispatcher.CurrentDispatcher);

        private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            // Stop the timer from ticking.
            myClickWaitTimer.Stop();

            Trace.WriteLine("Double Click");
            e.Handled = true;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            myClickWaitTimer.Start();
        }

        private static void mouseWaitTimer_Tick(object sender, EventArgs e)
        {
            myClickWaitTimer.Stop();

            // Handle Single Click Actions
            Trace.WriteLine("Single Click");
        }事件

相關文章
相關標籤/搜索