I have three canvases I’m using in a card game app I’m building. One is the main canvas that has the other two as child canvases (one static and one that will rotate):

In this sample app, I want to move the RotatingEl to the position on the StaticEl:

When i click the Move button, it works as expected:

Now, I want to Rotate the RotatingCanvas and still have the RotatingEl move to the StaticEl location AND adjust rotation to still match the StaticEl’s angle:

When I try it, it moves to the wrong location:

Here is my code on the Move Button Click:
GeneralTransform generalTransformStaticEl = StaticEl.TransformToVisual(MainCanvas);
Point pointstatic = generalTransformStaticEl.Transform(new Point());
GeneralTransform generalTransformRotEl = RotatingEl.TransformToVisual(MainCanvas);
Point pointrot = generalTransformRotEl.Transform(new Point());
double distancecalcX = pointstatic.X - pointrot.X;
double distancecalcY = pointstatic.Y - pointrot.Y;
DoubleAnimation ELMoveY = new DoubleAnimation();
ELMoveY.From = Canvas.GetTop(RotatingEl);
ELMoveY.To = Canvas.GetTop(RotatingEl)+(distancecalcY);
ELMoveY.Duration = new Duration(TimeSpan.FromSeconds(1.0));
DoubleAnimation ELMoveX = new DoubleAnimation();
ELMoveX.From = Canvas.GetLeft(RotatingEl);
ELMoveX.To = Canvas.GetLeft(RotatingEl)+(distancecalcX);
ELMoveX.Duration = new Duration(TimeSpan.FromSeconds(1.0));
RotatingEl.BeginAnimation(Canvas.LeftProperty, ELMoveX);
RotatingEl.BeginAnimation(Canvas.TopProperty, ELMoveY);
How can I adjusted the “To” of the animations to still move the Rotated canvas’s RotatingEl to the static StaticEl’s position AND adjust the rotation of the RotatingEl to match the StaticEl’s orientation?
I found my own solution. In case anyone may be interested, here is the updated code:
The generalTransformStaticEl required co-ordinates from the rotated canvas instead of the non-rotated MainCanvas. The adjustment to rotation was simply a matter of getting the Rotated canvas’s current rotation angle and multiplying by -1 to align with static rectangle