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.

The Navigation App Template, PageControl Structure, and<br />

PageControlNavigator<br />

Taking one step beyond the Blank App template, the Navigation App template demonstrates the basic<br />

use of page controls. (The more complex templates build navigation out further.) If you create a new<br />

project with this template in Visual Studio or Blend, here’s what you’ll get:<br />

• default.html Contains a single container div with a PageControlNavigator control pointing to<br />

pages/home/home.html as the app’s home page.<br />

• js/default.js Contains basic activation and state checkpoint code for the app.<br />

• css/default.css Contains global styles.<br />

• pages/home Contains a page control for the “home page” contents, composed of<br />

home.html, home.js, and home.css. Every page control typically has its own markup, script,<br />

and style files.<br />

• js/navigator.js Contains the implementation of the PageControlNavigator class.<br />

To build upon this structure, add additional pages by using a page control template. I recommend<br />

first creating a new folder for the page under pages, like home in the default project structure. Then<br />

right-click that folder, select Add > New Item, and select Page Control. This will create suitably named<br />

.html, .js. and .css files in that folder.<br />

Now let’s look at the body of default.html (omitting the standard header and a commented-out<br />

AppBar control):<br />

<br />

<br />

<br />

All we have here is a single container div named contenthost (it can be whatever you want), in which<br />

we declare the Application.PageControlNavigator control. With this we specify a single option to<br />

identify the first page control it should load (/pages/home/home.html). The PageControlNavigator will<br />

be instantiated within our activated handler’s call to WinJS.UI.processAll.<br />

Within home.html we have the basic markup for a page control. This is what the Navigation App<br />

template provides as a home page by default, and it’s pretty much what you get whenever you add a<br />

new PageControl from the item template:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

123

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

Saved successfully!

Ooh no, something went wrong!