LayoutTransformControl
The LayoutTransformControl applies a transform (rotation, scale, skew) to its child that participates in layout. Unlike RenderTransform, which only changes how a control is drawn without affecting surrounding layout, LayoutTransformControl causes parent panels to measure and arrange around the transformed bounds.
This means a rotated control will correctly push adjacent controls aside, and a scaled control will take up the appropriate amount of space in a StackPanel or Grid.
Common properties
| Property | Type | Description |
|---|---|---|
LayoutTransform | ITransform | The transform to apply during layout. Supports RotateTransform, ScaleTransform, SkewTransform, TransformGroup, and MatrixTransform |
UseRenderTransform | bool | When true, applies the transform via RenderTransform instead of a separate layout pass. Defaults to false |
Child | Control | The child control to transform (inherited from Decorator) |
Padding | Thickness | Padding around the child (inherited from Decorator) |
LayoutTransform vs. RenderTransform
| Affects layout | Yes, siblings reflow around transformed bounds | No, siblings ignore the transform |
| Performance | Re-measures and re-arranges on transform changes | Lightweight, GPU-accelerated |
| Use when | Surrounding content must respect the transformed size | Animating or visually adjusting without layout impact |
Examples
Rotating a control
This rotates a button 45 degrees. The parent StackPanel allocates space for the rotated bounds, so the text below is not overlapped:
- XAML
<StackPanel Spacing="8" HorizontalAlignment="Center" xmlns="https://github.com/avaloniaui"> <LayoutTransformControl> <LayoutTransformControl.LayoutTransform> <RotateTransform Angle="45" /> </LayoutTransformControl.LayoutTransform> <Button Content="Rotated 45°" /> </LayoutTransformControl> <TextBlock Text="This text is positioned below the rotated button." /> </StackPanel>
Scaling a control
You can scale a control to twice its size while keeping layout correct:
<LayoutTransformControl>
<LayoutTransformControl.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</LayoutTransformControl.LayoutTransform>
<TextBlock Text="Double size" />
</LayoutTransformControl>
Combining transforms
Use a TransformGroup to apply multiple transforms:
<LayoutTransformControl>
<LayoutTransformControl.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" />
<RotateTransform Angle="30" />
</TransformGroup>
</LayoutTransformControl.LayoutTransform>
<Border Background="LightBlue" Padding="12">
<TextBlock Text="Scaled and rotated" />
</Border>
</LayoutTransformControl>
Binding the angle
You can bind the rotation angle to a slider for interactive control:
<StackPanel Spacing="12">
<Slider x:Name="AngleSlider" Minimum="0" Maximum="360" Value="0" />
<LayoutTransformControl HorizontalAlignment="Center">
<LayoutTransformControl.LayoutTransform>
<RotateTransform Angle="{Binding #AngleSlider.Value}" />
</LayoutTransformControl.LayoutTransform>
<Border Background="LightCoral" Padding="16">
<TextBlock Text="Drag the slider to rotate" />
</Border>
</LayoutTransformControl>
</StackPanel>
Practical notes
- Performance: Because
LayoutTransformControltriggers a full measure and arrange pass whenever the transform changes, avoid animating itsLayoutTransformat high frequency. If you need smooth, frame-rate animations (such as a spinning icon), useRenderTransforminstead. - Nesting: You can nest a
LayoutTransformControlinside anotherLayoutTransformControl. Each one measures its child independently, so transforms compose outward through the layout tree. UseRenderTransform: Setting this property totrueapplies the transform throughRenderTransformrather than a separate layout pass. This can be useful when you want the convenience of declaring the transform inLayoutTransformsyntax but do not need surrounding controls to reflow.- Clipping: Parent containers that clip their children (for example, a
BorderwithClipToBounds="True") may clip the transformed bounds. Make sure the parent has enough space to display the full transformed area.