Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 4.29 KB

toastnotificationmanager_gettemplatecontent_687642458.md

File metadata and controls

67 lines (48 loc) · 4.29 KB
-api-id -api-type -api-device-family-note
M:Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(Windows.UI.Notifications.ToastTemplateType)
winrt method
xbox

Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent

-description

Gets the XML content of one of the predefined toast templates so that you can customize it for use in your notification.

-parameters

-param type

One of the system-provided toast templates.

-returns

The object that contains the template XML.

-remarks

Instead of creating the full XML payload yourself, you can get a template and then use Document Object Model (DOM) manipulation functions to customize the part of the content that you want to change. You package this XML in a ToastNotification and send it to the tile through the ToastNotifier that you create through the other methods of this class.

See tile schema for an explanation of tile elements and attributes.

-examples

The following example shows how to create and send a toast notification that includes text and images, including the use of the GetTemplateContent method.

var notifications = Windows.UI.Notifications;

// Get the toast notification manager for the current app.
var notificationManager = notifications.ToastNotificationManager;

// The getTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var template = notifications.toastTemplateType.toastImageAndText01;
var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType[template]);

// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.getElementsByTagName("image");
images[0].setAttribute("src", "images/toastImageAndText.png");

var textNodes = toastXml.getElementsByTagName("text");
textNodes.forEach(function (value, index) {
    var textNumber = index + 1;
    var text = "";
    for (var j = 0; j < 10; j++) {
        text += "Text input " + /*@static_cast(String)*/textNumber + " ";
    }
    value.appendChild(toastXml.createTextNode(text));
});

// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new notifications.ToastNotification(toastXml);

notificationManager.createToastNotifier().show(toast);

-see-also

Toast notifications sample, Sending toast notifications from desktop apps sample, Toast XML schema, Toast notification overview, Quickstart: Sending a toast notification, Quickstart: Sending a toast push notification, Quickstart: Sending a toast notification from the desktop, Guidelines and checklist for toast notifications, How to handle activation from a toast notification, How to opt in for toast notifications, How to schedule a toast notification, How to enable desktop toast notifications through an AppUserModelID, The toast template catalog, Toast audio options