Prev | Current Page 232 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"


nTip If you use the Canvas alongside other elements, you may want to consider setting its ClipToBounds to
True. That way, elements inside the Canvas that stretch beyond its bounds are clipped off at the edge of the
Canvas. (This prevents them from overlapping other elements elsewhere in your window.) All the other layout
containers always clip their children to fit, regardless of the ClipToBounds setting.
Z-Order
If you have more than one overlapping element, you can set the attached Canvas.ZIndex
property to control how they are layered.
Ordinarily, all the elements you add have the same ZIndex??”0. When elements have the
same ZIndex, they??™re displayed in the same order that they exist in Canvas.Children collection,
which is based on the order that they??™re defined in the XAML markup. Elements declared later
in the markup??”such as button (70,120)??”are displayed overtop of elements that are declared
earlier??”such as button (120,30).
However, you can promote any element to a higher level by increasing its ZIndex. That??™s
because higher ZIndex elements always appear over lower ZIndex elements. Using this technique,
you could reverse the layering in the previous example:
CHAPTER 4 n LAYOUT 108