I have a strange but big problem. I am trying to allow the user to move / rotate some rectangles on the canvas. I base my mechanism on managing Canvas.Left / Canvas.Top properties for moving and RenderTransform.Rotate for rotating. I only need rotation at angles 0/90/180/270.
The problem is that the rectangle, which is placed at the coordinates 0.0 when the angle 0 is rotated, shows ok, but the same rectangle, equal to 0.0 when the 90-degree rotation, shows the element in other coordinates than 0,0. As I can see, the coordinates are always correct in the case where the rotation is 0 or 180, but incorrect in the case of 90/270. The difference between what coordinates are set and what the user sees is related to the difference between height and width.
Has anyone encountered such a problem before?
Thanks Daniel
edit:
Of course, here are a few haml:
<Canvas Height="500" Width="500" Background="Green" <Rectangle Canvas.Left="0" Canvas.Top="0" Height="50" Width="100" RenderTransformOrigin="0.5,0.5" Fill="Red" <Rectangle.RenderTransform> <RotateTransform Angle="90" /> </Rectangle.RenderTransform> </Rectangle> <Rectangle Canvas.Left="0" Canvas.Top="0" Height="50" Width="100" RenderTransformOrigin="0.5,0.5" Fill="RoyalBlue" <Rectangle.RenderTransform> <RotateTransform Angle="0" /> </Rectangle.RenderTransform> </Rectangle> </Canvas> </Grid>
as you can see, the blue rectangle seems to be correctly placed (0,0), but the red one is displayed in different coordinates, even if it returns stil 0,0.
I found that the formula:
displayPointX = Canvas.Left + height / 2 - width / 2
diaplayPointY = Canvas.Top + height / 2 - width / 2
source share