Igor Adamenko
Igor Adamenko

Reputation: 143

Rotate Grid around cursor position?

I have this function:

private void RightTap_Rotate(object sender, RightTappedRoutedEventArgs e)
    {
        var obj = (CompositeTransform)N.RenderTransform;
        obj.Rotation += 90;

    }

So, after right-click to Grid (N) it's rotate to 90, but not around cursor position (around the left corner, yeah).

What I need to use for rotate it around cursor?

Upvotes: 0

Views: 175

Answers (1)

Weyland Yutani
Weyland Yutani

Reputation: 4960

Set the center point for the transformation:

private void RightTap_Rotate(object sender, RightTappedRoutedEventArgs e)
{
    var obj = (CompositeTransform)N.RenderTransform;
    Point cursorPos = Mouse.GetPosition(yourControl);
    obj.CenterX = cursorPos.X;
    obj.CenterY = cursorPos.Y;
    obj.Rotation += 90;
}

Upvotes: 1

Related Questions