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.

Hint Technically speaking, you can declare as many app bars as you want in whatever pages you want,<br />

and they’ll all be present in the DOM. However, the last one that gets processed in your markup will be<br />

the one that’s topmost in the z-index by default and therefore the one to receive events. Windows does<br />

not make any attempt to combine app bars, so because page controls are inserted into the middle of a<br />

host page like default.html, an app bar in default.html that’s declared after the page control host<br />

element will appear on top. At the same time, if the page control’s app bar is larger than that in<br />

default.html, a portion of it might be visible. The bottom line: declare app bars either in the host page<br />

or in a page control, but not both.<br />

App Bar Basics and Standard Commands<br />

As I just mentioned, an app bar can be declared once for an app in a container page like default.html or<br />

can be declared separately for each individual page control. The <strong>HTML</strong> AppBar control sample does the<br />

latter, because it provides very distinct app bars for its various scenarios.<br />

Scenario 1 of the sample (html/create-appbar.html) declares an app bar with four commands and a<br />

separator:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

This appears in the app as follows, using the ui-light.css stylesheet, in which we can also see a tooltip,<br />

a focus rectangle, and a hover effect on the Add command (I placed my mouse over the command to<br />

see all this):<br />

In the markup, the app bar control is declared like any other WinJS control (this is becoming a habit!)<br />

using some containing element (a div) with data-win-control="WinJS.UI.AppBar". Each page in this<br />

sample is loaded with WinJS.UI.Pages.render that conveniently calls WinJS.UI.processAll to<br />

instantiate the app bar. (It is also allowable, as with other controls, to create an app bar<br />

programmatically using the new operator.)<br />

278

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

Saved successfully!

Ooh no, something went wrong!