Populate the XmlDocument

Populate the XmlDocument in toastXml (code omitted) } var toast = new Notifications.ToastNotification(toastXml); notificationManager.createToastNotifier().show(toast); The following code from Scenario 3 (js/scenario3.js) demonstrates creating a toast with XML strings (toastImageAndText01). As with tiles, you can use ms-appx:///, ms-appdata:///local, or http:// URIs to refer to images (in-package, app data, and remote images, respectively): function displayWebImageToastWithStringManipulation(e) { // toastTemplateName is set according to the button you click var notificationManager = Notifications.ToastNotificationManager; var toastXmlString; if (templateName === "toastImageAndText01") { toastXmlString = "" + "" + "" + "Body text that wraps over three lines" + "" + "" + "" + ""; } else { // Other cases omitted } } var toastDOM = new Windows.Data.Xml.Dom.XmlDocument(); toastDOM.loadXml(toastXmlString); var toast = new Notifications.ToastNotification(toastDOM); notificationManager.createToastNotifier().show(toast); Butter and Jam: Options for Your Toast Beyond the properties you can assign when creating a ToastNotification object (or a ScheduledToastNotification), there are additional bits you can include within the XML, as described in the Toast schema: • The root toast element in the XML has optional launch and duration attributes. The launch attribute can be assigned a string that will be passed to the app’s activated handler as eventArgs.detail.arguments, exactly as happens with a secondary tile. (See “App Activation From a Secondary Tile” earlier in this chapter.) The duration attribute can have values of short (five seconds or the value from PC Settings > Ease of Access) or long (25 seconds or the value from PC Settings > Easy of Access, whichever is longer; refer back to Figure 13-7). • The visual and binding elements in the XML can have branding and addImageQuery attributes that act exactly like their counterparts for tiles. Refer back to the “Branding” and “Using Local and Web Images” sections under “Tiles, Secondary Tiles, and Badges.” The image element also 602

supports addImageQuery for scale, language, and contrast settings. • The visual, binding, and text elements support a lang attribute to identify the current app language. The toast element can also have a child audio element through which you can add a sound to a toast notification provided that the user has not disabled notification sounds altogether in PC Settings > Notifications. (Refer to Figure 13-8.) The particular sound is set with the src attribute and must be a one of the following string values as described in the Toast audio options catalog: 68 • ms-winsoundevent:Notification.Default • ms-winsoundevent:Notification.IM • ms-winsoundevent:Notification.Mail • ms-winsoundevent:Notification.Reminder • ms-winsoundevent:Notification.SMS • ms-winsoundevent:Notification.Looping.Alarm • ms-winsoundevent:Notification.Looping.Alarm2 • ms-winsoundevent:Notification.Looping.Call • ms-winsoundevent:Notification.Looping.Call2 Separately, the audio.silent attribute controls whether audio plays at all (false, the default) or is muted (true). If the toast.duration attribute is set and you set audio.src to one of the latter four “Looping” sounds above, you can also set audio.loop to true (to repeat the sound) or false (to play the sound only once, the default). Scenario 4 in the Toast notifications sample lets you play with the different notification sounds—different buttons choose different sounds. The text of each button (in a variable named toast-SoundSource) is appended to the ms-winsoundevent:Notification. as in this XML used to create the notification: "" Scenario 6 shows the use of the loop attribute in the XML as well: "" 68 With all the catalogs we’ve seen in this chapter, it feels like we’ve been shopping! More seriously, the fact that you must use audio from this list means that custom audio is not supported. 603