#1,058 – Translation Makes No Sense within Layout Transforms
April 24, 2014 Leave a comment
A layout transform is a transformation applied before a container’s child elements are laid out.
Because the container will position child elements after doing the layout transform, it doesn’t make sense to include a translation as part of a layout transform. The container positions its child elements based on its layout rules, deciding on the X and Y position of each element after you’ve done the layout transform.
If you want to translate an element relative to where the container wants to put it, you can do that by using the Margin property of the element or by applying a render transform.
Below, the second label uses a translate transform that is ignored. The third label does the translation in the render transform.
<StackPanel> <Label Content="Flavius" Background="AliceBlue" HorizontalAlignment="Left"/> <Label Content="Lucius" Background="Bisque" HorizontalAlignment="Left"> <Label.LayoutTransform> <TranslateTransform X="100"/> </Label.LayoutTransform> </Label> <Label Content="Constantine" Background="Gainsboro" HorizontalAlignment="Left"> <Label.RenderTransform> <TranslateTransform X="100"/> </Label.RenderTransform> </Label> </StackPanel>