23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using the first item’s dimension like this underscores the fact that a ListView with cell spanning will<br />

take more time to render because it must measure each item as it gets laid out, with or without the<br />

itemInfo function. For this reason, cell spanning is probably best avoided for large lists.<br />

Where all this gets a little more interesting, which the sample doesn’t show, is how the GridLayout<br />

deals with items that vary in width. Its basic algorithm is still to lay out columns from top to bottom and<br />

then left to right, but it will now infill empty spaces next to smaller items when larger ones create those<br />

gaps. To demonstrate this, let’s modify the sample so that the smallest item is 155x80 (half the original<br />

size), the medium item is 310x80, and the large item is 310x160. Here are the changes to make that<br />

happen:<br />

1. Undo any changes from the previous tests: in html/scenario4.html, add groupInfo back to<br />

data-win-options, and in js/data.js, change the class in the first item of myCellSpanningData<br />

back to smallListIconTextItem.<br />

2. In js/data.js, change the cellWidth in groupInfo to 155 (half of 310) and leave cellHeight at 80.<br />

For clarity, also insert an incrementing number at the start of each item’s text in<br />

myCellSpanningData array.<br />

3. In css/scenario4.css:<br />

a. Change the width of smallListIconTextItem to 145px. Applying the formula, ((145+10) * 1)<br />

– 10 = 145. Height is 70px.<br />

b. Change the width of mediumlListIconTextItem to 310px and the height to 70px.<br />

c. Change the width of largelListIconTextItem to 310px and the height to 160px. Applying<br />

the formula to the height, ((80+10) *2 ) – 10 = 170px.<br />

d. Set the width style in the #listview rule to 800px and the height to 600px (to make more<br />

space in which to see the layout).<br />

I recommend making these changes in Blend where your edits are reflected more immediately than<br />

running the app from Visual Studio. In any case, the results are shown in Figure 5-10 where the numbers<br />

show us the order in which the items are laid out (and apologies for clipping the text…experiments must<br />

make sacrifices at times!). A copy of the sample with these modifications is provided in the companion<br />

content for this chapter.<br />

221

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

Saved successfully!

Ooh no, something went wrong!