Latest News

  • New Rich Text Editor User Control
    Feb 19, 2010

    By popular request, here we present a re-usable User Control containing the Liquid RichTextBox along with the most common formatting functions included.

  • Silverlight 3 Controls V5.2.7 Released
    Feb 19, 2010

    This release includes several fixes for issues raised in the forum. The main improvement is to the RichTextBox which now provides access and methods to the document elements allowing...

  • Super Shoot Em Up Game
    Feb 04, 2010

    Added to the games section is the new Super Shoot 'Em Up game. Take control of a tank with your aim being to blow up your opposing tanks and collect all the powerups.

  • Silverlight 3 Controls V5.2.6 Released
    Feb 04, 2010

    This release includes some minor fixes for several forum posts. Please see the notes on the download page for full details on what has changed.

  • Chaos Tournament Game
    Jan 24, 2010

    Launched today is the new Games section which contains the new Silverlight only Chaos Tournament game. This game is a remake of a classic 1985 ZX Spectrum game Chaos.

Rendering Order with the Silverlight Z-Index Property

The order in which elements are rendered in Silverlight is determined firstly by where they appear in the visual object hierarchy and secondly by their Z-Index property.  Understanding this can be difficult at first but it is no different to the way browsers render plain HTML elements.

As I've said at the start the object hierarchy is the first part of the puzzle.  By object I mean a Canvas, Grid or StackPanel (any element derived from Panel), any object that can contain elements such as the TextBlock, Rectangle, Line etc.

<Canvas x:Name="parentCanvas"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Loaded="Page_Loaded"
        x:Class="ZIndex.Page;assembly=ClientBin/ZIndex.dll"
        Width="640"
        Height="480"
        Background="White"
        >
  <Canvas>
    <Rectangle Canvas.Left="40" Canvas.Top="40" Fill="#0000ff" Width="100" Height="100" />
    <Rectangle Canvas.Left="60" Canvas.Top="60" Fill="#4444ff" Width="100" Height="100" />
    <Rectangle Canvas.Left="80" Canvas.Top="80" Fill="#8888ff" Width="100" Height="100" />
    <Rectangle Canvas.Left="100" Canvas.Top="100" Fill="#bbbbff" Width="100" Height="100" />
  </Canvas>

  <Canvas Canvas.Top="200" Canvas.Left="200">
    <Rectangle Canvas.Left="0" Canvas.Top="0" Fill="#ff0000" Width="100" Height="100" Canvas.ZIndex="2" />
    <Rectangle Canvas.Left="20" Canvas.Top="20" Fill="#ff4444" Width="100" Height="100" />
    <Rectangle Canvas.Left="40" Canvas.Top="40" Fill="#ff8888" Width="100" Height="100" />
    <Rectangle Canvas.Left="60" Canvas.Top="60" Fill="#ffbbbb" Width="100" Height="100" />
  </Canvas>
</Canvas>

In the screenshot below you can see the first set of Rectangles (Blue) are rendered in order of appearance.  This is the default behaviour that Silverlight applies to elements when rendering them.

For the second set of rectangles (Red) the first rectangle is visible above the others, this is because of the Canvas.ZIndex setting.  Try playing with the settings to see what the effects are.

Screenshot showing two sets of rectangles

Using Canvas.ZIndex in a Grid

Just as you can apply the Canvas.ZIndex property to elements in a Canvas you can also use the Canvas.ZIndex property for elements in a Grid as well to control depth rendering order.

Post your Comments

Thanks for posting about silverlight Canvas.ZIndexProperty found the image displayed very helpful to easily understand.



Regards



KRK


Thank you for sharing this Nice Information


Silverlight Controls

  • Rich TextBox

    Create and edit rich content with this slick and expandable Rich TextBox...

  • TreeView

    This easy to use TreeView comes with drag and drop, sorting, searching and much more...

  • Context Menu

    You too can have cool popup context menus in your Silverlight applications...

  • Resizable Dialog

    Draggable and resizable popup dialogs are what serious Silverlight developers need...

  • Spell Checker

    Real-time spell checking in Silverlight? We did it first here...