ToastNotifier ToastNotifier ToastNotifier ToastNotifier Class

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

Syntax

Declaration

public sealed class ToastNotifierpublic sealed class ToastNotifierPublic NotInheritable Class ToastNotifierpublic sealed class ToastNotifier

Remarks

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

Examples

The following example shows how to create and send a toast notification that includes text and images, including use of the Show(ToastNotification) 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(ScheduledToastNotification) 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]);
    }
}

Properties summary

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

Methods summary

Adds a ScheduledToastNotification for later display by Windows.

Important

This method cannot be used by desktop callers.

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

Important

This method cannot be used by desktop callers.

Removes the specified toast notification from the screen.

Cancels the scheduled display of a specified ScheduledToastNotification.

Important

This method cannot be used by desktop callers.

Displays the specified toast notification.

Prerelease. Updates the existing toast notification that has the specified tag.

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

Properties

  • 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.

    public NotificationSetting Setting { get; }public NotificationSetting Setting { get; }Public ReadOnly Property Setting As NotificationSettingpublic NotificationSetting Setting { get; }

    Property Value

    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.

Methods

  • 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.

    public void AddToSchedule(ScheduledToastNotification scheduledToast)public void AddToSchedule(ScheduledToastNotification scheduledToast)Public Function AddToSchedule(scheduledToast As ScheduledToastNotification) As voidpublic void AddToSchedule(ScheduledToastNotification scheduledToast)

    Parameters

    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: AddToSchedule(ScheduledToastNotification) 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.

  • 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.

    public IVectorView<ScheduledToastNotification> GetScheduledToastNotifications()public IVectorView<ScheduledToastNotification> GetScheduledToastNotifications()Public Function GetScheduledToastNotifications() As IVectorView( Of ScheduledToastNotification )public IVectorView<ScheduledToastNotification> GetScheduledToastNotifications()

    Returns

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

    Remarks

    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]);
        }
    }
    
  • Hide(ToastNotification)
    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 voidpublic void Hide(ToastNotification notification)

    Parameters

    Remarks

    Call Hide(ToastNotification) 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.

  • 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.

    public void RemoveFromSchedule(ScheduledToastNotification scheduledToast)public void RemoveFromSchedule(ScheduledToastNotification scheduledToast)Public Function RemoveFromSchedule(scheduledToast As ScheduledToastNotification) As voidpublic void RemoveFromSchedule(ScheduledToastNotification scheduledToast)

    Parameters

    Remarks

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

    Examples

    The following example shows the use of the RemoveFromSchedule(ScheduledToastNotification) 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]);
        }
    }
    
  • Show(ToastNotification)
    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 voidpublic void Show(ToastNotification notification)

    Parameters

    Remarks

    Examples

    The following example shows how to create and send a toast notification that includes text and images, including use of the Show(ToastNotification) 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);
    
  • Update(NotificationData, String)
    Update(NotificationData, String)
    Update(NotificationData, String)
    Update(NotificationData, String)

    Prerelease. Updates the existing toast notification that has the specified tag.

    public NotificationUpdateResult Update(NotificationData data, String tag)public NotificationUpdateResult Update(NotificationData data, String tag)Public Function Update(data As NotificationData, tag As String) As NotificationUpdateResultpublic NotificationUpdateResult Update(NotificationData data, String tag)

    Parameters

    Returns

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

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

    public NotificationUpdateResult Update(NotificationData data, String tag, String group)public NotificationUpdateResult Update(NotificationData data, String tag, String group)Public Function Update(data As NotificationData, tag As String, group As String) As NotificationUpdateResultpublic NotificationUpdateResult Update(NotificationData data, String tag, String group)

    Parameters

    Returns

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute

Details

Assembly

Windows.UI.Notifications.dll