Condividi tramite


ToastNotificationManager.GetTemplateContent(ToastTemplateType) Metodo

Definizione

Ottiene il contenuto XML di uno dei modelli di avviso popup predefiniti in modo da poterlo personalizzare per l'uso nella notifica.

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

Parametri

type
ToastTemplateType

Uno dei modelli di avviso popup forniti dal sistema.

Restituisce

Oggetto contenente il codice XML del modello.

Esempio

Nell'esempio seguente viene illustrato come creare e inviare una notifica di tipo avviso popup che include testo e immagini, incluso l'uso del metodo 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);

Commenti

Anziché creare manualmente il payload XML completo, è possibile ottenere un modello e quindi usare le funzioni di manipolazione DOM (Document Object Model) per personalizzare la parte del contenuto che si desidera modificare. È possibile creare il pacchetto XML in un oggetto ToastNotification e inviarlo al riquadro tramite ToastNotifier creato tramite gli altri metodi di questa classe.

Per una spiegazione degli elementi e degli attributi dei riquadri , vedere Schema riquadro.

Si applica a

Vedi anche