Having problems with wpf and rotatetranformation
i am trying to rotate elements on a canvas and the save their rotated (not original) positions to a file. I implemented a custom UIElement control to display a custom graphic, however when the graphic is rotated on the screen it is rotated correctly (no problem there) however when i obtain the position of the element using GetValue(Canvas.LeftProperty) and GetValue(Canvas.TopProperty), the X, Y coordinates and the angle of the element is of position of the original image before rotation.
I am learning WPF to finish a project for school and thus my knowledge of the technology is not as vast as i would like but if anyone can help me i would greatly appreciate it, thank you.
this is the implementation of the code that i have:
CustomObject m;
List<CustomObject> co = new List<CustomObject>();
foreach (var child in canvas1.Children){
m = child as CustomObject;
if (m != null && m.IsEnabled && m.IsVisible){
SaveStructure m1 = new SaveStructure();
<b>m1.Angle = Convert.ToSingl开发者_如何学编程e(ToRadians(m.Angle));</b>
<b>m1.X = Convert.ToInt32(m.GetValue(Canvas.LeftProperty));</b>
<b>m1.Y = Convert.ToInt32(m.GetValue(Canvas.TopProperty));</b>
co.Add(m1);
}
}
Note: All i want to know is how to get the position of the rotated element on the canvas, because i keep obtaining the original (unrotated) position.
The position you get is still the same because the object was not moved, it was just rotated, if you want to get the bounds of the rotated object that is something different than getting its position. You could do that by getting the corner point coordinates of the elements (Canvas.GetLeft(m), Canvas.GetTop(m), Canvas.GetLeft(m) + m.Width, Canvas.GetTop(m) + m.Height
) and rotate them using the RotateTransform
's Transform(Point p)
method, then extract the bounds from those rotated points.
精彩评论