ToastNotificationManager 類別

定義

建立您用來引發快顯通知的 ToastNotifier 物件。 這個類別也可讓您存取系統提供的快顯通知範本的 XML 內容,以便自訂該內容以供通知使用。

public ref class ToastNotificationManager abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
class ToastNotificationManager final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ToastNotificationManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
public static class ToastNotificationManager
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public static class ToastNotificationManager
Public Class ToastNotificationManager
繼承
Object Platform::Object IInspectable ToastNotificationManager
屬性

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 引進)

範例

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

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

備註

從傳統型應用程式傳送快顯通知

一般而言,從傳統型應用程式傳送快顯通知與從 UWP 應用程式傳送通知相同。 不過,您應該注意這些差異和需求:

  • 若要讓傳統型應用程式顯示快顯通知,應用程式必須在 [開始] 畫面上具有快捷方式。
  • 快捷方式必須具有 AppUserModelID
  • 傳統型應用程式無法排程快顯通知。

如需詳細資訊,請參閱下列主題:

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1607 14393 ConfigureNotificationMirroring
1607 14393 GetForUser
1703 15063 GetDefault

屬性

History

取得 ToastNotificationHistory 物件。

方法

ConfigureNotificationMirroring(NotificationMirroring)

指定是否允許通知鏡像。 通知鏡像可讓通知在多個裝置上廣播。

CreateToastNotifier()

建立並初始化 ToastNotification的新實例,此實例系結至呼叫的應用程式,可讓您向該應用程式發出快顯通知。

CreateToastNotifier(String)

建立並初始化 ToastNotification的新實例,系結至指定的應用程式,通常是相同套件中的另一個應用程式。

GetDefault()

取得目前使用者的快顯通知管理員。

GetForUser(User)

取得指定使用者的快顯通知管理員。

GetTemplateContent(ToastTemplateType)

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

適用於

另請參閱