4

I need to make double click using touch down event in WPF

like double click in mouse down event.

if (e.ClickCount == 2) ;

Any Suggestion ?

1 Answers1

3

I found solution

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

Refrence Link

Community
  • 1
  • 1
  • Instead of hard coding the distance value you are using to check how close the taps are, and the duration between the taps, you should use `SystemInformation.DoubleClickTime` and `SystemInformation.DoubleClickSize`. More info available on [MSDN](https://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.doubleclicktime(v=vs.110).aspx) – Craig Feb 03 '15 at 11:27