Share via


ToastNotifier Klasse

Definition

Löst eine Popupbenachrichtigung für die bestimmte App aus, an die der ToastNotifier gebunden ist. Mit dieser Klasse können Sie auch Popupbenachrichtigungen planen und entfernen.

public ref class ToastNotifier sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class ToastNotifier final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ToastNotifier final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class ToastNotifier
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ToastNotifier
Public NotInheritable Class ToastNotifier
Vererbung
Object Platform::Object IInspectable ToastNotifier
Attribute

Windows-Anforderungen

Gerätefamilie
Windows 10 (eingeführt in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v1.0)

Beispiele

Das folgende Beispiel zeigt, wie Sie eine Popupbenachrichtigung erstellen und senden, die Text und Bilder enthält, einschließlich der Verwendung der Show-Methode .

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

Das folgende Beispiel zeigt die Verwendung der Methoden GetScheduledToastNotifications und RemoveFromSchedule .

var notifier = Notifications.ToastNotificationManager.createToastNotifier();
var scheduled = notifier.getScheduledToastNotifications();                    

for (var i = 0, len = scheduled.length; i < len; i++) {

    // The itemId value is the unique ScheduledTileNotification.Id assigned to the 
    // notification when it was created.
    if (scheduled[i].id === itemId) {
        notifier.removeFromSchedule(scheduled[i]);
    }
}

Hinweise

Wenn es erstellt wird, ist ToastNotifier an eine bestimmte App gebunden, sodass sich die Methoden dieser Klasse nur auf diese App auswirken.

Versionsverlauf

Windows-Version SDK-Version Wertschöpfung
1703 15063 Update(NotificationData,String,String)
1703 15063 Update(NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

Eigenschaften

Setting

Ruft einen Wert ab, der Ihnen angibt, ob eine App, ein Benutzer oder ein Systemblock vorhanden ist, der die Anzeige einer Popupbenachrichtigung verhindert.

Methoden

AddToSchedule(ScheduledToastNotification)

Fügt eine ScheduledToastNotification zur späteren Anzeige durch Windows hinzu.

Wichtig

Diese Methode wird nur in Anwendungen unterstützt, die WinRT als Standardanwendungsframework verwenden.

GetScheduledToastNotifications()

Ruft die Auflistung von ScheduledToastNotification-Objekten ab, die diese App für die Anzeige geplant hat.

Wichtig

Diese Methode wird nur in Anwendungen unterstützt, die WinRT als Standardanwendungsframework verwenden.

Hide(ToastNotification)

Entfernt die angegebene Popupbenachrichtigung vom Bildschirm.

RemoveFromSchedule(ScheduledToastNotification)

Bricht die geplante Anzeige einer angegebenen ScheduledToastNotification ab.

Wichtig

Diese Methode wird nur in Anwendungen unterstützt, die WinRT als Standardanwendungsframework verwenden.

Show(ToastNotification)

Zeigt die angegebene Popupbenachrichtigung an.

Update(NotificationData, String)

Updates die vorhandene Popupbenachrichtigung mit dem angegebenen Tag.

Update(NotificationData, String, String)

Updates die vorhandene Popupbenachrichtigung, die das angegebene Tag enthält und zur angegebenen Benachrichtigungsgruppe gehört.

Ereignisse

ScheduledToastNotificationShowing

Tritt auf, wenn das System die geplante Popupbenachrichtigung anzeigt.

Gilt für:

Weitere Informationen