08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

376<br />

CHAPTER 16 ■ PROGRAMMING SILVERLIGHT WITH XAML AND JAVASCRIPT<br />

In addition, you can set the Z-order of the Canvas using the Canvas.ZIndex attribute.<br />

Z-order determines which item is drawn on top of another if multiple items are overlapping<br />

on the screen. <strong>Silverlight</strong> reads a XAML file from the top down, so that items that<br />

appear later in the document will be drawn on top of items that appear earlier.<br />

Here is an example of a XAML document containing two Canvases. Each Canvas contains<br />

a rectangle.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

There are a number of things going on in this listing, which, once you underst<strong>and</strong><br />

them, will help you to underst<strong>and</strong> how to lay elements out in <strong>Silverlight</strong> XAML.<br />

First, notice that each of the rectangles is contained within a Canvas. The first, or<br />

white, rectangle (the one with the Fill="White" attribute set) has its Canvas.Top property<br />

set to 19. This means that it will be drawn 19 pixels down from its container. Its container<br />

Canvas has a Canvas.Top of 59 <strong>and</strong> a Canvas.Left of 8. This Canvas is contained by the root<br />

Canvas—thus, the white rectangle will be drawn 78 pixels down from the top of the<br />

screen <strong>and</strong> 8 pixels from the left. Similarly, the black rectangle’s position is determined by<br />

its Canvas.Top <strong>and</strong> Canvas.Left properties relative to its container Canvas.<br />

Next, you will notice that the dimensions of the rectangles are set so that they are<br />

actually overlapping <strong>and</strong> occupying some of the same screen real estate. As mentioned<br />

earlier, <strong>Silverlight</strong> will draw later elements on top of earlier ones, so the black rectangle<br />

should be drawn on top of the white one.<br />

Figure 16-1 shows how this will appear when it is rendered.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!