0

I want to accomplish the following scenario. I have a UIElement with a CompositeTransform which I want to drag around the screen. Plus, when I’m tapping on it, I want it to rotate by 90 degrees. So, I’m handling Tap ManipulationStarted ManipulationDelta -> there I’m increasing Translate.X and Y by e.DeltaManipulation.Translation.X and Y ManipulationCompleted

When the CompositeTransform.Rotation is 0, everything works fine. However, when it’s > 0 (e.g. 90), the e.DeltaManipulation.Translation gives me values relative to the rotation of the object! So, I’m trying to move the UIElement on the right of the screen but it moves up…

Any hints?

Jose Luis
  • 3,307
  • 3
  • 36
  • 53

1 Answers1

0

I have the position values (Top & Left) bound to the Canvas and the rotation value bound to a rotationtransform angle. During my ManipulationDelta event, I use these two lines:

piece.Left = piece.Left + (Math.Cos(piece.Radians)*e.DeltaManipulation.Translation.X) - (Math.Sin(piece.Radians) * e.DeltaManipulation.Translation.Y);
piece.Top = piece.Top + (Math.Cos(piece.Radians) * e.DeltaManipulation.Translation.Y) + (Math.Sin(piece.Radians) * e.DeltaManipulation.Translation.X);

I should mention that I only rotate by 90 degrees at a time. I think this wouldn't work if you have arbitrary angles. But the sine and cosine functions will get you there with a little editing if you're doing arbitrary angles.

Plus, you said you wanted a hint...

Lee McPherson
  • 931
  • 6
  • 20