From the course: Windows Presentation Foundation: 2 Layout

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Overlay elements with ZIndex

Overlay elements with ZIndex

From the course: Windows Presentation Foundation: 2 Layout

Start my 1-month free trial

Overlay elements with ZIndex

- [Instructor] Some of the layout panels in WPF support the overlapping of their children. Two of the common panels that support overlapping are the grid and the canvas. When you have two elements overlap then you have to have a way of determining which one is shown on top of the other or closer to the user. When you think about traditional 3D space we have an X axis and a Y axis and a Z axis. And the Z axis is usually the one that points towards the user. So, in WPF, you won't be surprised to find that there's a property called the ZIndex. By changing the ZIndex value, you can move an item closer to the user or put it back to the back of the stack. In my example here I have a canvas with two letterboxes. letterbox D is here, it's first in the canvas. And letterbox A is second in the canvas. If you look at the designer, you'll see that letterbox A is shown on top of letterbox D. So, that implies that even though I don't explicitly set a ZIndex value here, it's created by the canvas…

Contents