• <tfoot id='HMQrT'></tfoot>
  • <legend id='HMQrT'><style id='HMQrT'><dir id='HMQrT'><q id='HMQrT'></q></dir></style></legend>
      <bdo id='HMQrT'></bdo><ul id='HMQrT'></ul>

    <i id='HMQrT'><tr id='HMQrT'><dt id='HMQrT'><q id='HMQrT'><span id='HMQrT'><b id='HMQrT'><form id='HMQrT'><ins id='HMQrT'></ins><ul id='HMQrT'></ul><sub id='HMQrT'></sub></form><legend id='HMQrT'></legend><bdo id='HMQrT'><pre id='HMQrT'><center id='HMQrT'></center></pre></bdo></b><th id='HMQrT'></th></span></q></dt></tr></i><div id='HMQrT'><tfoot id='HMQrT'></tfoot><dl id='HMQrT'><fieldset id='HMQrT'></fieldset></dl></div>

      <small id='HMQrT'></small><noframes id='HMQrT'>

      1. 如何在 WPF FrameworkElement 上同时捕获单击和双击事件?

        时间:2023-09-15

          <legend id='g5tq6'><style id='g5tq6'><dir id='g5tq6'><q id='g5tq6'></q></dir></style></legend>
          • <i id='g5tq6'><tr id='g5tq6'><dt id='g5tq6'><q id='g5tq6'><span id='g5tq6'><b id='g5tq6'><form id='g5tq6'><ins id='g5tq6'></ins><ul id='g5tq6'></ul><sub id='g5tq6'></sub></form><legend id='g5tq6'></legend><bdo id='g5tq6'><pre id='g5tq6'><center id='g5tq6'></center></pre></bdo></b><th id='g5tq6'></th></span></q></dt></tr></i><div id='g5tq6'><tfoot id='g5tq6'></tfoot><dl id='g5tq6'><fieldset id='g5tq6'></fieldset></dl></div>
              <bdo id='g5tq6'></bdo><ul id='g5tq6'></ul>
                <tbody id='g5tq6'></tbody>
              <tfoot id='g5tq6'></tfoot>

                • <small id='g5tq6'></small><noframes id='g5tq6'>

                  本文介绍了如何在 WPF FrameworkElement 上同时捕获单击和双击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以像这样在 TextBlock 上捕获单击:

                  I can catch a single-click on a TextBlock like this:

                  private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
                  {
                      MessageBox.Show("you single-clicked");
                  }
                  

                  我可以像这样在 TextBlock 上捕获 双击:

                  I can catch a double-click on a TextBlock like this:

                  private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
                  {
                      if (e.LeftButton == MouseButtonState.Pressed)
                      {
                          if (e.ClickCount == 2)
                          {
                              MessageBox.Show("you double-clicked");
                          }
                      }
                  }
                  

                  但是如何在单个 TextBlock 上同时捕捉它们并区分两者?

                  推荐答案

                  您需要在点击序列结束后触发事件……那是什么时候?我建议使用计时器.MouseDown 事件将重置它并增加点击次数.当计时器间隔过去时,它会调用以评估点击次数.

                  You need to fire the event after the click sequence is over... when is that? I suggest using a timer. The MouseDown event would reset it and increase the click count. When timer interval elapses it makes the call to evaluate the click count.

                      private System.Timers.Timer ClickTimer;
                      private int ClickCounter;
                  
                      public MyView()
                      {
                          ClickTimer = new Timer(300);
                          ClickTimer.Elapsed += new ElapsedEventHandler(EvaluateClicks);
                          InitializeComponent();
                      }
                  
                      private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
                      {
                          ClickTimer.Stop();
                          ClickCounter++;
                          ClickTimer.Start();
                      }
                  
                      private void EvaluateClicks(object source, ElapsedEventArgs e)
                      {
                          ClickTimer.Stop();
                          // Evaluate ClickCounter here
                          ClickCounter = 0;
                      }
                  

                  干杯!

                  这篇关于如何在 WPF FrameworkElement 上同时捕获单击和双击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 WPF 上下文菜单项单击事件处理程序中引用右键单击的对象? 下一篇:创建一个事件来观察变量的变化

                  相关文章

                    <legend id='1IbKH'><style id='1IbKH'><dir id='1IbKH'><q id='1IbKH'></q></dir></style></legend>
                    <tfoot id='1IbKH'></tfoot>
                    • <bdo id='1IbKH'></bdo><ul id='1IbKH'></ul>

                    <small id='1IbKH'></small><noframes id='1IbKH'>

                  1. <i id='1IbKH'><tr id='1IbKH'><dt id='1IbKH'><q id='1IbKH'><span id='1IbKH'><b id='1IbKH'><form id='1IbKH'><ins id='1IbKH'></ins><ul id='1IbKH'></ul><sub id='1IbKH'></sub></form><legend id='1IbKH'></legend><bdo id='1IbKH'><pre id='1IbKH'><center id='1IbKH'></center></pre></bdo></b><th id='1IbKH'></th></span></q></dt></tr></i><div id='1IbKH'><tfoot id='1IbKH'></tfoot><dl id='1IbKH'><fieldset id='1IbKH'></fieldset></dl></div>