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.

FIGURE 5-4 ListView elements as shown in the Grid App template home page. (All colored items are added labels<br />

and lines.)<br />

There’s quite a bit going on with the ListView in this project, so we’ll take one part at a time. For<br />

starters, the control’s markup in pages/groupedItems/groupedItems.html is very basic, where the only<br />

option is to indicate that the items have no selection behavior:<br />

<br />

<br />

Switching over to pages/groupedItems/groupedItems.js, the page’s ready method handles<br />

initialization:<br />

ready: function (element, options) {<br />

var listView = element.querySelector(".groupeditemslist").winControl;<br />

listView.groupHeaderTemplate = element.querySelector(".headerTemplate");<br />

listView.itemTemplate = element.querySelector(".itemtemplate");<br />

listView.oniteminvoked = this._itemInvoked.bind(this);<br />

// (Keyboard handler initialization omitted)...<br />

this.initializeLayout(listView, appView.value);<br />

listView.element.focus();<br />

},<br />

Here you can see that the control’s templates can be set in code just as easily as from markup, and in<br />

this case we’re using a class to locate the template element instead of an id. Why does this work? It’s<br />

because we’ve actually been referring to elements the whole time: the app host automatically creates a<br />

variable for an element that’s named the same as its id. It’s the same thing. In code you can also provide<br />

192

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

Saved successfully!

Ooh no, something went wrong!