WPF button 同时处理两个事件时候会先触发click事件,触发doubleclick事件  ,那如何区分呢,可以这样设置:

  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");
        }

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2021-07-01
  • 2022-01-14
  • 2022-03-03
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案