ToastNotificationManager.GetTemplateContent(ToastTemplateType) 方法

定義

取得其中一個預先定義的快顯通知範本的 XML 內容,以便自訂它以用於通知中。

public:
 static XmlDocument ^ GetTemplateContent(ToastTemplateType type);
 static XmlDocument GetTemplateContent(ToastTemplateType const& type);
public static XmlDocument GetTemplateContent(ToastTemplateType type);
function getTemplateContent(type)
Public Shared Function GetTemplateContent (type As ToastTemplateType) As XmlDocument

參數

type
ToastTemplateType

其中一個系統提供的快顯通知範本。

傳回

包含範本 XML 的物件。

範例

下列範例示範如何建立並傳送包含文字和影像的快顯通知,包括使用 GetTemplateContent 方法。

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);

備註

您可以取得範本,然後使用檔物件模型 (DOM) 操作函式來自訂您想要變更的內容部分,而不是自行建立完整的 XML 承載。 您會將此 XML 封裝在 ToastNotification 中,並透過您透過這個類別的其他方法建立的 ToastNotifier 將它傳送至磚。

如需磚元素和屬性的說明,請參閱 磚架構

適用於

另請參閱