#480 – ZIndex Values and Render Transforms
January 25, 2012 1 Comment
It’s possible for controls to overlap each other when using a RenderTransform–even in containers that don’t normally overlap their child controls.
In the example below, the first Button in a StackPanel is rotated and ends up overlapping the second Button.
<StackPanel Margin="10"> <Button Content="Alpha" HorizontalAlignment="Center" Padding="20,0" > <Button.RenderTransform> <RotateTransform Angle="45"/> </Button.RenderTransform> </Button> <Button Content="Bravo" HorizontalAlignment="Center" Padding="20,0" /> </StackPanel>
Whenever overlapping occurs, the containing panel’s attached ZIndex property dictates the overlapping order of the child controls. With default ZIndex values of 0, child controls appearing later in the XAML are rendered on top of earlier controls.
You can explicitly control the overlap order by specifying ZIndex values. In the previous example, if we give the first button a ZIndex of 2 and the second button a ZIndex of 1, their overlap order is reversed.