TapGestureRecouncer interferes with PanGestureRecouncer

50 views Asked by At

In my code, I am reading the movement of a finger within a specified area using PanGestureRecognizer. However, I encountered an issue where the PanGestureRecognizer event is not triggered when tapping twice, as TapGestureRecognizer interferes with it. My question is how to resolve this issue.

To make the problem more understandable, I have a video to demonstrate the issue.

code:

<Border>
    <Border.GestureRecognizers>
        <PanGestureRecognizer PanUpdated="Touchpad_PanUpdate"/>
    </Border.GestureRecognizers>
</Border>

back:

private void Touchpad_PanUpdate(object sender, PanUpdatedEventArgs e)
{
    if (e.StatusType == GestureStatus.Running)
    {
        DebugRunningLabel.Text = "x/y: " + Math.Round(e.TotalX, 2) + " " + Math.Round(e.TotalY, 2);
    }
}
1

There are 1 answers

1
Alexandar May - MSFT On

The PanGestureRecognizer event is not triggered when tapping twice.

Tapping twice on the screen is not related with the PanGestureRecognizer, it's related with TapGestureRecognizer. You can't mix them together.

If you want to make a View recognize a tap gesture with double taps, you can create a TapGestureRecognizer object, handle the Tapped event, set NumberOfTapsRequired="2" and add the new gesture recognizer to the GestureRecognizers collection on the view.

The following code example shows a TapGestureRecognizer attached to an Image with tapping twice:

XAML:

<Image Source="dotnet_bot.png">
    <Image.GestureRecognizers>
        <TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped"
                              NumberOfTapsRequired="2" />
  </Image.GestureRecognizers>
</Image>

C#:

void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
{
    // Handle the tap
}