23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Populate the XmlDocument in toastXml (code omitted)<br />

}<br />

var toast = new Notifications.ToastNotification(toastXml);<br />

notificationManager.createToastNotifier().show(toast);<br />

The following code from Scenario 3 (js/scenario3.js) demonstrates creating a toast with XML strings<br />

(toastImageAndText01). As with tiles, you can use ms-appx:///, ms-appdata:///local, or http:// URIs to<br />

refer to images (in-package, app data, and remote images, respectively):<br />

function displayWebImageToastWithStringManipulation(e) {<br />

// toastTemplateName is set according to the button you click<br />

var notificationManager = Notifications.ToastNotificationManager;<br />

var toastXmlString;<br />

if (templateName === "toastImageAndText01") {<br />

toastXmlString = ""<br />

+ ""<br />

+ ""<br />

+ "Body text that wraps over three lines"<br />

+ ""<br />

+ ""<br />

+ ""<br />

+ "";<br />

} else {<br />

// Other cases omitted<br />

}<br />

}<br />

var toastDOM = new Windows.Data.Xml.Dom.XmlDocument();<br />

toastDOM.loadXml(toastXmlString);<br />

var toast = new Notifications.ToastNotification(toastDOM);<br />

notificationManager.createToastNotifier().show(toast);<br />

Butter and Jam: Options for Your Toast<br />

Beyond the properties you can assign when creating a ToastNotification object (or a<br />

ScheduledToastNotification), there are additional bits you can include within the XML, as described in<br />

the Toast schema:<br />

• The root toast element in the XML has optional launch and duration attributes. The launch<br />

attribute can be assigned a string that will be passed to the app’s activated handler as<br />

eventArgs.detail.arguments, exactly as happens with a secondary tile. (See “App Activation<br />

From a Secondary Tile” earlier in this chapter.) The duration attribute can have values of short<br />

(five seconds or the value from PC Settings > Ease of Access) or long (25 seconds or the value<br />

from PC Settings > Easy of Access, whichever is longer; refer back to Figure 13-7).<br />

• The visual and binding elements in the XML can have branding and addImageQuery attributes<br />

that act exactly like their counterparts for tiles. Refer back to the “Branding” and “Using Local<br />

and Web Images” sections under “Tiles, Secondary Tiles, and Badges.” The image element also<br />

602

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

Saved successfully!

Ooh no, something went wrong!