Toast​Notifier Toast​Notifier Toast​Notifier Class

Definition

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, IToastNotifier2public sealed class ToastNotifier : IToastNotifier, IToastNotifier2Public NotInheritable Class ToastNotifier Implements IToastNotifier, IToastNotifier2
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

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

public : NotificationSetting Setting { get; }public NotificationSetting Setting { get; }Public ReadOnly Property Setting As NotificationSetting
Value
NotificationSetting NotificationSetting NotificationSetting

Enabled if the toast can be shown; otherwise, one or more reasons that the toast will be blocked.

Attributes

Remarks

When toast notifications have been disabled at more than one level, this property value reflects the setting with the largest scope. Precedence is as follows, from largest scope to smallest:

  1. DisabledByManifest
  2. DisabledByGroupPolicy
  3. DisabledForUser
  4. DisabledForApplication If toast notifications have been disabled both by the user and by group policy, this property returns DisabledByGroupPolicy.
See Also

Methods

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

Adds a ScheduledToastNotification for later display by Windows.

Important

This method cannot be used by desktop callers.

public : void AddToSchedule(ScheduledToastNotification scheduledToast)public void AddToSchedule(ScheduledToastNotification scheduledToast)Public Function AddToSchedule(scheduledToast As ScheduledToastNotification) As void
Parameters
scheduledToast
ScheduledToastNotification ScheduledToastNotification ScheduledToastNotification

The scheduled toast notification, which includes its content and timing instructions.

Attributes

Remarks

This method passes the toast notification to the schedule but doesn't specify the time the toast should display. That information is included in the ScheduledToastNotification.

If your call to this method returns a failure code, examine these possible causes:

  • Possible cause: You've exceeded the maximum allowed number of scheduled notifications.

Fix: ToastNotifier.addToSchedule will fail if you attempt to schedule more than 4096 notifications. Reduce your number of scheduled notifications.

  • Possible cause: Your notification is scheduled for a time in the past relative to the current system clock time.

Fix: Make sure that the scheduled notification time specified in your ScheduledToastNotification is in the future. Examine the system clock time.

See Also

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.

public : IVectorView<ScheduledToastNotification> GetScheduledToastNotifications()public IReadOnlyList<ScheduledToastNotification> GetScheduledToastNotifications()Public Function GetScheduledToastNotifications() As IReadOnlyList( Of ScheduledToastNotification )
Returns
Windows.Foundation.Collections.IVectorView<Windows.UI.Notifications.ScheduledToastNotification> Windows.Foundation.Collections.IVectorView<Windows.UI.Notifications.ScheduledToastNotification> Windows.Foundation.Collections.IVectorView<Windows.UI.Notifications.ScheduledToastNotification>

The collection of scheduled toast notifications that the app bound to this notifier has scheduled for timed display.

Attributes

Examples

The following example shows the use of the GetScheduledToastNotifications method.


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

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

Removes the specified toast notification from the screen.

public : void Hide(ToastNotification notification)public void Hide(ToastNotification notification)Public Function Hide(notification As ToastNotification) As void
Parameters
notification
ToastNotification ToastNotification ToastNotification

The object that specifies the toast to hide.

Attributes

Remarks

Call Hide if the situation or action that caused the app to raise the toast is no longer an issue. This method should only be called when the app is in the foreground.

For Windows Phone Store app: this method also removes the toast notification from the action center.

See Also

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

Cancels the scheduled display of a specified ScheduledToastNotification.

Important

This method cannot be used by desktop callers.

public : void RemoveFromSchedule(ScheduledToastNotification scheduledToast)public void RemoveFromSchedule(ScheduledToastNotification scheduledToast)Public Function RemoveFromSchedule(scheduledToast As ScheduledToastNotification) As void
Parameters
scheduledToast
ScheduledToastNotification ScheduledToastNotification ScheduledToastNotification

The notification to remove from the schedule.

Attributes

Examples

The following example shows the use of the RemoveFromSchedule method.

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

If you want to cancel one or more scheduled toast notifications, you can use the GetScheduledToastNotifications method to get the full list.

See Also

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

Displays the specified toast notification.

public : void Show(ToastNotification notification)public void Show(ToastNotification notification)Public Function Show(notification As ToastNotification) As void
Parameters
notification
ToastNotification ToastNotification ToastNotification

The object that contains the content of the toast notification to display.

Attributes

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(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);
See Also

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

Updates the existing toast notification that has the specified tag.

public : NotificationUpdateResult Update(NotificationData data, PlatForm::String tag)public NotificationUpdateResult Update(NotificationData data, String tag)Public Function Update(data As NotificationData, tag As String) As NotificationUpdateResult
Parameters
data
NotificationData NotificationData NotificationData

An object that contains the updated info.

tag
System.String System.String System.String

The identifier of the toast notification to update.

Returns

A value that indicates the result of the update (failure, success, etc).

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

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.

public : NotificationUpdateResult Update(NotificationData data, PlatForm::String tag, PlatForm::String group)public NotificationUpdateResult Update(NotificationData data, String tag, String group)Public Function Update(data As NotificationData, tag As String, group As String) As NotificationUpdateResult
Parameters
data
NotificationData NotificationData NotificationData

An object that contains the updated info.

tag
System.String System.String System.String

The identifier of the toast notification to update.

group
System.String System.String System.String

The ID of the ToastCollection that contains the notification.

Returns

A value that indicates the result of the update (failure, success, etc).

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

See Also