Canvas.ZIndex attached property

XAML Values

An integer value that establishes the element's index in the z-order for rendering, when the Canvasis composed. You typically use values 0 and greater but negative values are permitted. See Remarks.

Remarks

Canvas.ZIndex declares the draw order for the child elements of a Canvas. This matters when there is overlap between any of the bounds of the child elements. A higher z-order value will draw on top of a lower z-order value. If no value is set, the default is -1. If there is a draw order issue where elements share one or more pixels of layout space in a Canvas and the z-index values are the same, then the last element declared in XAML (or the highest index element in the Children collection if using code) is the element that draws on top.

You can also set the Canvas.ZIndex value to a negative value, such as -99, which places the object even farther from the foreground than any default value.

Canvas.ZIndex is an attached property, which supports a XAML usage. When setting this property in code, use SetZIndex. When getting this property in code, use GetZIndex. In code usages, the target parameter is the object where the attached property value is set. Another way to get or set the value in code is to use the dependency property system, calling either GetValue or SetValue and passing ZIndexProperty as the dependency property identifier.

A Canvas.ZIndex value is interpreted by the most immediate parent Canvas element from where the value is set. The value is used to explicitly define the draw order in cases where child elements overlap.