I am using the drag gesture to move elements on a canvas. I am using the pinch gesture to zoom/tranlate the size of the canvas. What I want to do now is move the entire canvas based on the movement of both fingers in a pinch. I know I can do this with the move, but I need that for items on the canvas itse开发者_JAVA百科lf, and sometimes the entire canvas is covered with items that would make it so you could not select the canvas to move it.
Is this possible with the PinchGestureEventArgs?
I am sure you have solved this a long time ago, but I was recently doing something similar myself:
In the PinchDelta event you receive a PinchGestureEventArgs.
You can use the GetPosition method on the event to discover the positions of both fingers (passing the index second parameter), although in this case you only need the first finger.
By checking that the DistanceRatio indicates the distance between the fingers has not changed much since the pinch started, you can check whether this is a drag or a pinch, and move the canvas based on the position reported by GetPosition().
You'll need to maintain some state, to remember the last position you handled, so that you can calculate the delta.
精彩评论