共用方式為


ToastNotifier.Show(ToastNotification) 方法

定義

顯示指定的快顯通知。

public:
 virtual void Show(ToastNotification ^ notification) = Show;
void Show(ToastNotification const& notification);
public void Show(ToastNotification notification);
function show(notification)
Public Sub Show (notification As ToastNotification)

參數

notification
ToastNotification

物件,包含要顯示的快顯通知內容。

範例

下列範例示範如何建立並傳送包含文字和影像的快顯通知,包括使用 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(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);

適用於