0

我有我移动和旋转的图形(网格)。它们放置在父网格(名称:字段)中,因此,对于移动,我使用 TranslateX,对于旋转:

private void RightTap_Rotate(object sender, RightTappedRoutedEventArgs e)
    {
        var obj = sender as Grid;
        var objTransform = (CompositeTransform)obj.RenderTransform;
        Point cursorPos = e.GetPosition(obj);

        objTransform.CenterX = cursorPos.X;
        objTransform.CenterY = cursorPos.Y;

        objTransform.Rotation += 90;     
    }

即我围绕它的中心旋转Figure。但是旋转后我找不到图形和字段的正确相对位置。我用那个:

private void Object_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        var obj = sender as Grid;
        var objTransform = (CompositeTransform)obj.RenderTransform;

        var transform = Field.TransformToVisual(obj);
        Point relativePosition = transform.TransformPoint(new Point(0, 0));

        //then I use relativePosition.X/Y
    }

我想获取形状左上角相对于字段左上角的坐标,但显然在旋转后出现问题。

请帮帮我。

4

1 回答 1

1

在您的代码中,您将一个点从父对象转换为子对象。相反,您希望从子对象转换为父对象。

var obj = sender as Grid;

var transform = obj.TransformToVisual(Field);
Point parentPoint = transform.TransformPoint(new Point(0, 0));
于 2013-10-11T16:11:13.110 回答