locked
RootGrid_ManipulationCompleted firing twice

    Question

  • I use manipulation completed to detect left and right swipes, however, the manipulation completed event is firing twice, why is this? 

    Its causing an issue in my games math, because its subtracting twice.

     private void rootGrid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
            {
                if (e.Velocities.Linear.X < -1)
                {
                    // rtl swipe
                    GameManager.NextGuess();
                }
                else if (e.Velocities.Linear.X > 1)
                {
                    // ltr swipe
                    GameManager.PreviousGuess();
                }
            }

    This is what manipulation completed is calling, but it runs twice.

    Tuesday, February 10, 2015 10:36 PM

Answers

  • How are you hooking up the event? Usually this means the app set up the event handler twice.

    A common cause is to hook up the handler in NavigatedTo but not to unhook it in NavigatedFrom.

    --Rob

    • Marked as answer by Fullmetal99012 Thursday, February 12, 2015 3:42 PM
    Wednesday, February 11, 2015 1:51 AM
    Owner
  • You'll need to provide more information. That's not normal behaviour, but you haven't shown enough of what you're doing to give an idea of how you're getting there.

    Can you share a minimal sample which reproduces the problem on your OneDrive?

    • Marked as answer by Fullmetal99012 Thursday, February 12, 2015 3:42 PM
    Thursday, February 12, 2015 1:19 AM
    Owner

All replies

  • How are you hooking up the event? Usually this means the app set up the event handler twice.

    A common cause is to hook up the handler in NavigatedTo but not to unhook it in NavigatedFrom.

    --Rob

    • Marked as answer by Fullmetal99012 Thursday, February 12, 2015 3:42 PM
    Wednesday, February 11, 2015 1:51 AM
    Owner
  • its hooked up in the xaml.

     the manipulation completed event property is set to the above method in the xaml properties of the grid

    Wednesday, February 11, 2015 2:50 AM
  • You'll need to provide more information. That's not normal behaviour, but you haven't shown enough of what you're doing to give an idea of how you're getting there.

    Can you share a minimal sample which reproduces the problem on your OneDrive?

    • Marked as answer by Fullmetal99012 Thursday, February 12, 2015 3:42 PM
    Thursday, February 12, 2015 1:19 AM
    Owner
  • I put a breakpoint on the code i'm firing to test the swipe events. that's how I found the issue. I'll have to throw together a modern app and see if that fires twice. perhaps its localized to my xaml page.

    or maybe i did something stupid and have two grids set to the same handler.

    Thursday, February 12, 2015 3:09 PM
  • I had two grids linked to my event, and both were picking up the swipes.
    Thursday, February 12, 2015 3:42 PM