ToastNotifier ToastNotifier ToastNotifier ToastNotifier ToastNotifier Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Raises a toast notification to the specific app to which the ToastNotifier is bound. This class also lets you schedule and remove toast notifications.

public : sealed class ToastNotifier : IToastNotifier, IToastNotifier2
struct winrt::Windows::UI::Notifications::ToastNotifier : IToastNotifier, IToastNotifier2
public sealed class ToastNotifier : IToastNotifier, IToastNotifier2
Public NotInheritable Class ToastNotifier Implements IToastNotifier, IToastNotifier2
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following example shows how to create and send a toast notification that includes text and images, including use of the Show method.


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

The following example shows the use of the GetScheduledToastNotifications and RemoveFromSchedule methods.


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

Remarks

When it is created, ToastNotifier is bound to a specific app, so the methods of this class affect only that app.

Properties

Setting Setting Setting Setting Setting

Gets a value that tells you whether there is an app, user, or system block that prevents the display of a toast notification.

Methods

AddToSchedule(ScheduledToastNotification) AddToSchedule(ScheduledToastNotification) AddToSchedule(ScheduledToastNotification) AddToSchedule(ScheduledToastNotification) AddToSchedule(ScheduledToastNotification)

Adds a ScheduledToastNotification for later display by Windows.

Important

This method cannot be used by desktop callers.

GetScheduledToastNotifications() GetScheduledToastNotifications() GetScheduledToastNotifications() GetScheduledToastNotifications() GetScheduledToastNotifications()

Gets the collection of ScheduledToastNotification objects that this app has scheduled for display.

Important

This method cannot be used by desktop callers.

Hide(ToastNotification) Hide(ToastNotification) Hide(ToastNotification) Hide(ToastNotification) Hide(ToastNotification)

Removes the specified toast notification from the screen.

RemoveFromSchedule(ScheduledToastNotification) RemoveFromSchedule(ScheduledToastNotification) RemoveFromSchedule(ScheduledToastNotification) RemoveFromSchedule(ScheduledToastNotification) RemoveFromSchedule(ScheduledToastNotification)

Cancels the scheduled display of a specified ScheduledToastNotification.

Important

This method cannot be used by desktop callers.

Show(ToastNotification) Show(ToastNotification) Show(ToastNotification) Show(ToastNotification) Show(ToastNotification)

Displays the specified toast notification.

Update(NotificationData, String) Update(NotificationData, String) Update(NotificationData, String) Update(NotificationData, String) Update(NotificationData, String)

Updates the existing toast notification that has the specified tag.

Update(NotificationData, String, String) Update(NotificationData, String, String) Update(NotificationData, String, String) Update(NotificationData, String, String) Update(NotificationData, String, String)

Updates the existing toast notification that has the specified tag and belongs to the specified notification group.

See Also