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)
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.
You can rotate shapes by using their RotationAngle property: XAML.
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.
Controls in WPF support graphical transformations. We can scale, skew, rotate and translate controls. We use the RenderTransform element.
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>
<Button ...> <Button.LayoutTransform> <RotateTransform CenterX="0.5" CenterY="0.5" Angle="90"/> </Button.LayoutTransform> </Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With