通过UIElement.TranslatePoint是childElement中心的计算,从正确值的偏差

问题描述 投票:0回答:1

我有与它周围的一些元素,所述用户可以通过鼠标旋转的矩形。作为这样的作品与RotateTransform旋转,但总有一种轻微的旋转中心的偏移量。我计算这样的中心:

this.rotationCenter = this.cornerA.CalculatePointOnLine(this.cornerC, 0.5);

CornerA和CornerC是长方形的四个角和建立一个角。现在,我想设置相对于相应的元素都RotateTransforms的中心。

Logger.Logger.Write("coord.log", "center : " + this.rotationCenter.X + " ; " + this.rotationCenter.Y);
this.rotateSurroundingRectangle.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.suroundingRectangle).X;
this.rotateSurroundingRectangle.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.suroundingRectangle).Y;

Logger.Logger.Write("coord.log", "relative center : " + this.rotateSurroundingRectangle.CenterX + " ; " + this.rotateSurroundingRectangle.CenterY);

this.rotateResizeCorner1.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner1).X;
this.rotateResizeCorner1.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner1).Y;
this.rotateResizeCorner2.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner2).X;
this.rotateResizeCorner2.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner2).Y;
this.rotateResizeCorner3.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner3).X;
this.rotateResizeCorner3.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner3).Y;
this.rotateResizeCorner4.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner4).X;
this.rotateResizeCorner4.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.resizeCorner4).Y;
this.rotateRotationSign.CenterX = this.ParentLayer.TranslatePoint(this.rotationCenter, this.rotationSign).X;
this.rotateRotationSign.CenterY = this.ParentLayer.TranslatePoint(this.rotationCenter, this.rotationSign).Y;

根据不同的角度,该中心周围的矩形所有元素应该改变,但是矩形本身的中心应该永远是32,32。但值偏离和X和Y的范围从29到35的值,我已经检查rotationCenter的计算,这是正确的。这是为什么偏差ocuring,我该如何解决?谢谢...

c# uielement
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.