1
votes

I've created a line object in my Silverlight 5 Application through code, now I want to rotate this line around its center point, but the behavior is strange, so that line is being rotated around top left corner of the screen, this is my code:

                    RotateTransform rotate = new RotateTransform();
                rotate.Angle = myArrowAngle[i] + off_x;
                myLines[i].RenderTransformOrigin = new Point(0.5d, 0.5d);
                myLines[i].RenderTransform = rotate;

what is going wrong? I set RenderTransferOrigin of my line object, but there is no luck, should I move my object after or before the rotate transform? how is this rotation done? in model space or in world space? it seems that it is being rotated in world space as my line is rotated around (0,0) point of my canvas rather than its center

1

1 Answers

2
votes

When you set the transform origin to 0.5,0.5, you set it relative to the "bounding box" of the line, which does not necessarily coincide with the center of the line itself.

See the following example:

<Canvas>
    <Line X1="0" Y1="50" X2="100" Y2="50"
          StrokeThickness="4" Stroke="Red" RenderTransformOrigin="0.5,0.5">
        <!--<Line.RenderTransform>
            <RotateTransform Angle="45" CenterX="0.5" CenterY="0.5"  />
        </Line.RenderTransform>-->
    </Line>
</Canvas>

Line in canvas

If you uncomment the transform, it will be applied from where the small circle is in that box.

Could that explain what you are experiencing?