Bagikan melalui


ToastNotificationManager.GetTemplateContent(ToastTemplateType) Metode

Definisi

Mendapatkan konten XML dari salah satu templat toast yang telah ditentukan sebelumnya sehingga Anda bisa menyesuaikannya untuk digunakan dalam pemberitahuan Anda.

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

Parameter

type
ToastTemplateType

Salah satu templat roti panggang yang disediakan sistem.

Mengembalikan

Objek yang berisi XML templat.

Contoh

Contoh berikut menunjukkan cara membuat dan mengirim pemberitahuan toast yang menyertakan teks dan gambar, termasuk penggunaan metode 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);

Keterangan

Alih-alih membuat payload XML lengkap sendiri, Anda bisa mendapatkan templat lalu menggunakan fungsi manipulasi Model Objek Dokumen (DOM) untuk menyesuaikan bagian konten yang ingin Anda ubah. Anda mengemas XML ini dalam ToastNotification dan mengirimkannya ke petak melalui ToastNotifier yang Anda buat melalui metode lain dari kelas ini.

Lihat skema petak peta untuk penjelasan tentang elemen dan atribut petak peta.

Berlaku untuk

Lihat juga