本文介绍了在多点触控屏幕上捕捉双击触控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了另一个问题,即如何通过监视 TouchDown 事件上的触摸之间的时间跨度来手动"捕获双击,但它有很多问题.有谁知道在多点触控屏幕上捕获双击的标准 Microsoft 方式/事件?

I've posted another question of how to 'manually' capture a double-tap by monitoring a timespan between touches on a TouchDown event, but it's quite buggy. Does anyone know of a standard Microsoft way/event of capturing double-tap on a multi-touch screen?

非常感谢,

推荐答案

我检查了点击位置和秒表的组合,完美运行!

I check the combination of the tap location and a stopwatch, and it works perfect!

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

public event EventHandler DoubleTouchDown;

protected virtual void OnDoubleTouchDown()
{
    if (DoubleTouchDown != null)
        DoubleTouchDown(this, EventArgs.Empty);
}

private bool IsDoubleTap(TouchEventArgs e)
{
    Point currentTapPosition = e.GetTouchPoint(this).Position;
    bool tapsAreCloseInDistance = currentTapPosition.GetDistanceTo(_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 OnPreviewTouchDown(object sender, TouchEventArgs e)
{
    if (IsDoubleTap(e))
        OnDoubleTouchDown();
}

它会在 PreviewTouchDown 中检查它是否是 DoubleTap.

It checks in the PreviewTouchDown whether or not it's an DoubleTap.

这篇关于在多点触控屏幕上捕捉双击触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 07:18