How to rotate around a control center in XAML

I want to rotate the button to 90 degrees, but it is cropped because it rotates arount (0,0). How to make it rotate around the center if I don’t know what is the width in pixels (this is a template for many buttons)

+57
c # wpf xaml
Nov 09 '10 at 9:35 on
source share
3 answers
<Button ...> <Button.LayoutTransform> <RotateTransform CenterX="0.5" CenterY="0.5" Angle="90"/> </Button.LayoutTransform> </Button> 
+37
Nov 09 '10 at 9:48 on
source share

You must set the RenderTransformOrigin control to 0.5, 0.5.

eg:.

 <Button RenderTransformOrigin="0.5, 0.5"> <RepeatButton.RenderTransform> <RotateTransform Angle="90"/> </RepeatButton.RenderTransform> </RepeatButton> 
+85
Nov 09 '10 at 9:40
source share

I understand that the source is not related to LayoutTransform.

MSDN says:

Conversion settings provide powerful scaling and rotation capabilities. However, LayoutTransform ignores TranslateTransform operations. This is because the behavior of the system layout for the child FrameworkElement elements automatically corrects any offsets for the position of the scaled or rotated element in the layout and system coordinates of the parent element.

and the next "right" turns the button.

 <Grid ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Button Grid.Row="1" Grid.Column="1">Excessively Long Button Still Ok <Button.LayoutTransform> <RotateTransform Angle="90" /> </Button.LayoutTransform> </Button> </Grid> 
+2
Nov 09 '10 at 10:05
source share



All Articles