Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do rotation around control's center in XAML

Tags:

c#

wpf

xaml

I want do rotate button to 90 degrees but it gets clipped because it rotates arount (0,0). How to make it rotate around center if I don't know it't width in pixels (it's a template for many buttons)

like image 230
Poma Avatar asked Nov 09 '10 09:11

Poma


People also ask

How do I rotate an image in XAML?

This article demonstrates how to rotate and translate images in WPF and XAML. Image transformation is a process of rotating and scaling images. There are two ways to rotate an image. First option is to use the Rotation property of BitmapImage and second option is use a TransformBitmap image.

How do you rotate a shape in WPF?

You can rotate shapes by using their RotationAngle property: XAML.

How do I rotate text in WPF?

The following code example uses a RotateTransform to rotate text. An Angle value of 90 rotates the element 90 degrees clockwise. The following example shows the second line of text scaled by 150% along the x-axis, and the third line of text scaled by 150% along the y-axis.

What is WPF RenderTransform?

Controls in WPF support graphical transformations. We can scale, skew, rotate and translate controls. We use the RenderTransform element.


2 Answers

You have to set the control's RenderTransformOrigin to 0.5, 0.5.

ex.:

<Button RenderTransformOrigin="0.5, 0.5">     <RepeatButton.RenderTransform>         <RotateTransform Angle="90"/>     </RepeatButton.RenderTransform> </RepeatButton> 
like image 74
Francesco De Vittori Avatar answered Sep 28 '22 23:09

Francesco De Vittori


<Button ...>   <Button.LayoutTransform>     <RotateTransform CenterX="0.5" CenterY="0.5" Angle="90"/>   </Button.LayoutTransform> </Button> 
like image 25
Andy Avatar answered Sep 28 '22 23:09

Andy