Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

Controlling the Z-Order

File Details
Downloads: 456 File Size: 31kB
Posted By: aatwal Views: 1891
Date Added: 19 Oct 2006

Thanks to Lorin Catudio for helping to provide this sample.

 

The ZIndex property determines the order in which child elements that share the same coordinate space appear.  A higher value will appear above a lower value.  For example, an element that has a value of 5 will appear above an element that has a value of 4.  Negative values are allowed.  The default indexing order is determined by the order in which elements appear in the visual tree.  This is also true for members of the same collection that share the same ZIndex value.

 

The following code results in the default indexing order shown in the figure below.


Photobucket - Video and Image Hosting

 

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

  <Rectangle Height="60" Width="60" Fill="Gold"/>

  <Rectangle Height="50" Width="70" Fill="Coral"/>

  <Rectangle Height="40" Width="80" Fill="Teal"/>

  <Rectangle Height="30" Width="90" Fill="Black"/>

</Canvas>

 

The following code results in the custom indexing order shown in the figure below.


Photobucket - Video and Image Hosting

 

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

  <Rectangle Canvas.ZIndex="99" Height="60" Width="60" Fill="Gold"/>

  <Rectangle Canvas.ZIndex="98" Height="50" Width="70" Fill="Coral"/>

  <Rectangle Canvas.ZIndex="97" Height="40" Width="80" Fill="Teal"/>

  <Rectangle Canvas.ZIndex="96" Height="30" Width="90" Fill="Black"/>

</Canvas>

Comments
No comments exist for this file.

Add Comment

Name (required)
Web Site (optional)
Comment (required)
Add

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us