我有我移动和旋转的图形(网格)。它们放置在父网格(名称:字段)中,因此,对于移动,我使用 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
}
我想获取形状左上角相对于字段左上角的坐标,但显然在旋转后出现问题。
请帮帮我。