zetar
zetar

Reputation: 1233

How does RotateTransform work? Can I change the point on the rectangle where it rotates?

I don't understand how RenderTransform offset works. I want to rotate a rectangle around a point. Specifically, I want the rectangle to rotate around a point that's half of the width. Here's a screenshot: enter image description here

Here's the code:

   RotateTransform rotateTransform1 = new RotateTransform(angle, 0 , 0  );

        myRectangle.RenderTransform = rotateTransform1;

I've tried different values to replace the 0s (like width / 2). This seems to change where on the screen the center of rotation is. What I need to change is what part of the rectangle that it rotates around. Specifically, I want the rectangle to rotate around a point that's the middle of its width.

Is it even possible to adjust the point of the rectangle where it rotates?

Upvotes: 0

Views: 213

Answers (1)

ASh
ASh

Reputation: 35680

use RenderTransformOrigin

RenderTransformOrigin has a somewhat nonstandard use of the Point structure value, in that the Point does not represent an absolute location in a coordinate system. Instead, values between 0 and 1 are interpreted as a factor for the range of the current element in each x,y axis. For example, (0.5,0.5) will cause the render transform to be centered on the element, or (1,1) would place the render transform at the bottom right corner of the element.

myRectangle.RenderTransformOrigin = new Point(0.5,0.5);
myRectangle.RenderTransform = rotateTransform1;

Upvotes: 1

Related Questions