Panel.ZIndex Attached Property
Gets or sets a value that represents the order on the z-plane in which an element appears.
Assembly: PresentationFramework (in PresentationFramework.dll)
The greater the value of a given element, the more likely the element is to appear in the foreground. Likewise, if an element has a relatively low value, the element will likely appear in the background. For example, an element that has a value of 5 will appear above an element that has a value of 4, which in turn will appear above an element that has a value of 3, and so on. Negative values are allowed, and they continue this precedence pattern.
Members of a Children collection that have equal ZIndex values are rendered in the order in which they appear in the visual tree. You can determine the index position of a child by iterating the members of the Children collection.
Identifier field | |
Metadata properties set to true | None |
The following example demonstrates how to set the value of the ZIndex property by using Extensible Application Markup Language (XAML) and code.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="ZIndex Sample"> <Canvas> <Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/> <Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="150" Canvas.Left="150" Fill="yellow"/> <Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="200" Canvas.Left="200" Fill="green"/> <!-- Reverse the order to illustrate z-index property --> <Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="300" Canvas.Left="200" Fill="green"/> <Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="350" Canvas.Left="150" Fill="yellow"/> <Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="400" Canvas.Left="100" Fill="blue"/> </Canvas> </Page>