locked
How to differentiate scale/translation/rotation gesture from manipulation events

    Question

  • According to MSDN documentation, scale, translation, and rotation gesture all raise the manipulation events (ManipulationStarted, ManipulationUpdate, and ManipulationComplete). So given a sequence of manipulation events, how can I tell which gesture raises these events?

    The second question is what events does a two-finger pinch (or stretch) gesture raise, what events does a mouse wheel rotation raise? 

    Friday, August 10, 2012 5:02 PM

Answers

  • The manipulations are passed in the event args. You get the results of the manipulation in ManipulationUpdatedEventArgs.Cumulative and Delta, but not how they were generated. If your ManipulationDelta structure includes a Rotation value then you know the user rotated. If it includes a Scale then the user did a rotate. If it includes both then the user did both.

    The overall concept is the same if you use UIElement manipulation events instead of the GestureRecognizer, but the details will be slightly different.

    --Rob

    • Marked as answer by Leonard Monday, August 13, 2012 3:53 PM
    Friday, August 10, 2012 5:55 PM
    Owner

All replies

  • The manipulations are passed in the event args. You get the results of the manipulation in ManipulationUpdatedEventArgs.Cumulative and Delta, but not how they were generated. If your ManipulationDelta structure includes a Rotation value then you know the user rotated. If it includes a Scale then the user did a rotate. If it includes both then the user did both.

    The overall concept is the same if you use UIElement manipulation events instead of the GestureRecognizer, but the details will be slightly different.

    --Rob

    • Marked as answer by Leonard Monday, August 13, 2012 3:53 PM
    Friday, August 10, 2012 5:55 PM
    Owner
  • Thanks for your response, Rob.

    While I think the unified approach using manipulations to represent all kinds of gestures makes sense, this approach make it difficult for programmers to customize the functions of certain gestures. In a map application for example, mouse wheel rotation gesture is usually used as zooming (or scale), whereas this same gesture also results in panning (or translation) in WinRT APIs. Although I managed to set MouseWheelParameters and do some tricks in my code to do the job, my method is unintuitive and may not work in the future.

    Saturday, August 11, 2012 4:18 PM
  • Mapping is part of my app and I've found the following works (it may not be right but it works!):

    1. Use an OnPointerWheelChanged event to handle the mouse wheel

    2. Have OnManipulationDelta handler distinguish between touch and mouse events. For touch, allow translation and scaling. For mouse, allow only translation.

    I haven't done any true touch testing, just used the simulator's touch-via-mouse mode, but it appears to work as one would expect.

    Saturday, August 11, 2012 4:38 PM
  • Thanks, henador.
    Monday, August 13, 2012 3:53 PM