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.

function itemInfo(itemIndex) {<br />

//determine values for itemWidth and itemHeight given itemIndex<br />

return {<br />

newColumn: false,<br />

itemWidth: itemWidth,<br />

itemHeight: itemHeight<br />

};<br />

}<br />

Clearly, this function will be called for every item in the list but only if cell spanning has been turned<br />

on through the groupInfo function. Again, unless your list is relatively small, you’ll very much improve<br />

performance by providing item dimensions through this function, but be sure to return as quickly as<br />

you can.<br />

You probably also noticed that newColumn property in the return value. As you might guess, setting<br />

this to true instructs the GridLayout to start a new column with this item, allowing you to control that<br />

particular behavior. You can even use newColumn by itself, if you like, with a smallish list.<br />

Now you might be asking: what happens if I set different sizes in my item template but don’t actually<br />

announce cell spanning? Well, you’ll end up with overlapping (and rather confusing) items. This is<br />

because the GridLayout takes the first item in a group as the basic measure for the rest of the items (and<br />

the backdrop grid as well). It does not attempt to automatically size each item according to content. Try<br />

this with Scenarios 4 or 5: remove the layout.groupInfo property from the ListView’s data-winoptions<br />

in html/scenario4.html or html/scenario5.html and restart the app, and you’ll see the medium and large<br />

items bleeding into those that follow:<br />

Then go into js/data.js, set the first item’s style in the myCellSpanningData array to be<br />

largeListIconTextItem, and restart; the ListView then does layout with that as the basic item size:<br />

220

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

Saved successfully!

Ooh no, something went wrong!