(双击)WPF中的Touch Down事件?

时间:2014-12-24 12:54:55

标签: wpf

我需要在double click using touch down event

中制作WPF

喜欢双击鼠标按下事件。

if (e.ClickCount == 2) ;

有任何建议吗?

1 个答案:

答案 0 :(得分:3)

我找到了解决方案

private readonly Stopwatch _doubleTapStopwatch = new Stopwatch();
        private Point _lastTapLocation;

        public static double GetDistanceBetweenPoints(Point p, Point q)
        {
            double a = p.X - q.X;
            double b = p.Y - q.Y;
            double distance = Math.Sqrt(a * a + b * b);
            return distance;
        }
        private bool IsDoubleTap(TouchEventArgs e)
        {
            Point currentTapPosition = e.GetTouchPoint(this).Position;
            bool tapsAreCloseInDistance = GetDistanceBetweenPoints(currentTapPosition, _lastTapLocation) < 40;
            _lastTapLocation = currentTapPosition;

            TimeSpan elapsed = _doubleTapStopwatch.Elapsed;
            _doubleTapStopwatch.Restart();
            bool tapsAreCloseInTime = (elapsed != TimeSpan.Zero && elapsed < TimeSpan.FromSeconds(0.7));

            return tapsAreCloseInDistance && tapsAreCloseInTime;
        }

  private void Close_OnTouchDown(object sender, TouchEventArgs e)
        {

            if(IsDoubleTap(e)) 
                //Do somthing;
         }

参考Link