#447 – You Can Use Layout Transforms Within a DockPanel
December 9, 2011 1 Comment
You can use a LayoutTransform on individual child elements in a DockPanel container to scale or rotate the elements.
In the example below, we have four Label controls, each docked to one side of a DockPanel. The labels on the left, top and right sides use a LayoutTransform to make them face outwards.
<DockPanel LastChildFill="False">
<Label Content="Facing Up" DockPanel.Dock="Top" Background="Aquamarine"
HorizontalContentAlignment="Center">
<Label.LayoutTransform>
<RotateTransform Angle="180"/>
</Label.LayoutTransform>
</Label>
<Label Content="Facing Down" DockPanel.Dock="Bottom" Background="LightSteelBlue"
HorizontalContentAlignment="Center">
</Label>
<Label Content="Facing Left" DockPanel.Dock="Left" Background="DarkSeaGreen"
HorizontalContentAlignment="Center">
<Label.LayoutTransform>
<RotateTransform Angle="90"/>
</Label.LayoutTransform>
</Label>
<Label Content="Facing Right" DockPanel.Dock="Right" Background="SkyBlue"
HorizontalContentAlignment="Center">
<Label.LayoutTransform>
<RotateTransform Angle="-90"/>
</Label.LayoutTransform>
</Label>
</DockPanel>