Dani
Dani

Reputation: 1047

WinRT Z-Index in page

Is the Canvas.ZIndex for a hole page? I was trying to move a element in the background below all other elements. I set the ZIndex the particular element to -1 but nothing happend. The element is still in the front.

Is there an other possibility to change the order?

Thanks

I've a grid with 1 row and 1 column. On this grid I put 2 other grids. On my first grid I draw lines, on the second are some borders. (There are a lot of other controls) like here

<Grid>
    <Grid>
        lines
    </Grid>
    <Grid>
        borders
        rectangles
    </Grid>
</Grid>

Now the lines should be drawn over the borders but under the rectangles.

How can I do that?

Upvotes: 1

Views: 774

Answers (2)

Nanning
Nanning

Reputation: 1

ZIndex is local. So all the elements in the first grid will be either drawn first (as in your current example), or last if either of those Grids has a ZIndex.

If you want interleave then you should have

<Grid>border</Grid>
<Grid>lines</Grid>
<Grid>rectangles</Grid>

Setting ZIndex on an element which is not a direct child of Canvas does nothing.

The Canvas draw loop is a bit like this

// make unique small-to-big list of all ZIndex of all elements of a canvas
var zvalues = canvas.elements.Select(ZIndex).Unique().Sort(DESC);
// draw them back to front
foreach (var z in zvalues) {
    foreach (var e in canvas.elements.Where(e=>e.ZIndex==z)) {
        e.Draw();
    }
}

Upvotes: 0

Jerry Nixon
Jerry Nixon

Reputation: 31831

You influence z-index in XAML two ways:

  1. You put things logically after (or below) other items in your XAML
  2. You use Canvas and set Canvas.ZIndex.

Those are your options.

Upvotes: 4

Related Questions