roryok
roryok

Reputation: 9645

Windows 8 / XAML Double Tap event always preceded by Tap

I've got a button in an app. I want it to do different things depending on whether I tap it (pause an animation) or double-tap (restart the animation)

however, when I double-tap, it seems to fire the tap event first and then the double-tap in quick succession. Is there a way around this? Is this a known issue or am I making a rookie mistake?

Edit: For those asking, I'm using the Tapped and DoubleTapped events.

Upvotes: 8

Views: 4061

Answers (3)

Neelesh Suryawanshi
Neelesh Suryawanshi

Reputation: 26

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern uint GetDoubleClickTime();
    bool _singleTapped = false;

        //Tapped event handler
        private async void control_Tapped(object sender, TappedRoutedEventArgs e)
        {
        _singleTapped = true;
            //var x = GetDoubleClickTime();
            //GetDoubleClickTime() gets the maximum number of milliseconds that can elapse between a first click and a second click
            await Task.Delay(TimeSpan.FromMilliseconds(GetDoubleClickTime()));

            if (!_singleTapped)
            { return; }
           //SingleTapped code
        }

        //DoubleTapped event handler
        private async void control_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            _singleTapped = false;
            //DoubleTapped code
        }

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 187

Give the some pause to single tab . If there is double tab occur then single tab event eliminated

  bool singleTap;
    private async void control_Tapped_1(object sender, TappedRoutedEventArgs e)
    {
        this.singleTap = true;
        await Task.Delay(200);
        if (this.singleTap)
        {
              // Single tab Method .
        }
    }

    private void control_DoubleTapped_1(object sender, DoubleTappedRoutedEventArgs e)
    {
        this.singleTap = false;

        // Double tab Method  
  }

Upvotes: 18

Ben Cull
Ben Cull

Reputation: 9504

You might want to consider letting it do both. Think about it like double clicking a folder in windows. Users will be used to something happening on the first click (highlighting the folder) and they will be expecting the double click to both highlight, then navigate.

All in all it seems like a design issue, not a technical one.

Upvotes: 4

Related Questions