This documentation is archived and is not being maintained.

ShapeElement.ZOrder Property

Determines the order in which this shape will be displayed relative to other shapes on the diagram. Normally set from the order of child shapes.

Namespace:  Microsoft.VisualStudio.Modeling.Diagrams
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.dll)

public virtual double ZOrder { get; set; }

Property Value

Type: System.Double

You are recommended not to set the value directly, because the Diagram sets the ZOrder of all its shapes as part of the painting process. Instead, to change the order in which shapes are displayed, re-order the shapes in the NestedChildShapesor RelativeChildShapes, and then call shape.Diagram.NeedsRenumber = true. This makes sure that the Diagram resets the ZOrders. See the following example.

    /// <summary>
    /// Command to send current shapes to the back.
    /// </summary>
    private void OnMenuSendShapesToBackCommand(object sender, EventArgs e)
      MenuCommand command = sender as MenuCommand;
      Store store = this.CurrentDocData.Store;
      foreach (object selectedItem in this.CurrentSelection)
        ShapeElement shape = selectedItem as ShapeElement;
        if (shape == null || shape.ParentShape == null) continue;
        if (shape.IsNestedChild)
          using (Transaction t = store.TransactionManager.BeginTransaction("sendToBack"))
            // Make the current shape the first in the list.
            shape.ParentShape.NestedChildShapes.Move(shape, 0);
            // Update the ZOrder of the shapes to reflect the change.
            shape.Diagram.NeedsRenumber = true;
            // Make sure the shape is redrawn:

To make sure that your shape always appears at the top of the diagram, you can override this property as follows.

/// <summary>
/// Gets the relative Z-Order for this ShapeElement.
/// Make sure that my shape stays above all other diagram elements.
///  Add a million to the Z-Order that we are given.
/// </summary>
public override double ZOrder
    return base.ZOrder + 1e6;
  // leave set{ } as inherited