ToastNotifier 類別

定義

將快顯通知引發至 ToastNotifier 所系結的特定應用程式。 此類別也可讓您排程和移除快顯通知。

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
繼承
Object Platform::Object IInspectable ToastNotifier
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

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

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

下列範例示範如何使用 GetScheduledToastNotificationsRemoveFromSchedule 方法。

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

備註

建立時,ToastNotifier 會系結至特定應用程式,因此此類別的方法只會影響該應用程式。

版本歷程記錄

Windows 版本 SDK 版本 新增值
1703 15063 更新 (NotificationData,String,String)
1703 15063 更新 (NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

屬性

Setting

取得值,這個值會告訴您是否有應用程式、使用者或系統區塊會防止顯示快顯通知。

方法

AddToSchedule(ScheduledToastNotification)

新增 ScheduledToastNotification 以供 Windows 稍後顯示。

重要

只有使用 WinRT 作為預設應用程式架構的應用程式才支援這個方法。

GetScheduledToastNotifications()

取得此應用程式已排程顯示之 ScheduledToastNotification 物件的集合。

重要

只有使用 WinRT 作為預設應用程式架構的應用程式才支援這個方法。

Hide(ToastNotification)

從畫面移除指定的快顯通知。

RemoveFromSchedule(ScheduledToastNotification)

取消指定 ScheduledToastNotification的排程顯示。

重要

只有使用 WinRT 作為預設應用程式架構的應用程式才支援這個方法。

Show(ToastNotification)

顯示指定的快顯通知。

Update(NotificationData, String)

更新具有指定標籤的現有快顯通知。

Update(NotificationData, String, String)

更新具有指定標籤且屬於指定通知群組的現有快顯通知。

事件

ScheduledToastNotificationShowing

發生于系統顯示排程的快顯通知時。

適用於

另請參閱