ToastNotificationManager ToastNotificationManager ToastNotificationManager ToastNotificationManager Class

Creates ToastNotifier objects that you use to raise toast notifications. This class also provides access to the XML content of the system-provided toast templates so that you can customize that content for use in your notifications.

Syntax

Declaration

public static class ToastNotificationManagerpublic static class ToastNotificationManagerPublic Static Class ToastNotificationManagerpublic static class ToastNotificationManager

Remarks

Sending toast notifications from desktop apps

Generally, sending a toast notification from a desktop app is the same as sending it from a Windows Store app. However, you should be aware of these differences and requirements:

  • For a desktop app to display a toast, the app must have a shortcut on the Start screen.
  • The shortcut must have an AppUserModelID.
  • Desktop apps cannot schedule a toast.

For more information, see these topics:

Examples

The following example shows how to create and send a toast notification that includes text and images, including the use of the GetTemplateContent(ToastTemplateType) and CreateToastNotifier() methods.


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

Properties summary

Gets the ToastNotificationHistory object.

Methods summary

Specifies whether notification mirroring is allowed. Notification mirroring enables a notification to be broadcast on multiple devices.

Creates and initializes a new instance of the ToastNotification, bound to the calling application, that lets you raise a toast notification to that app.

Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.

Prerelease. Gets a toast notification manager for the current user.

Gets a toast notification manager for the specified user.

Gets the XML content of one of the predefined toast templates so that you can customize it for use in your notification.

Properties

Methods

  • ConfigureNotificationMirroring(NotificationMirroring)
    ConfigureNotificationMirroring(NotificationMirroring)
    ConfigureNotificationMirroring(NotificationMirroring)
    ConfigureNotificationMirroring(NotificationMirroring)

    Specifies whether notification mirroring is allowed. Notification mirroring enables a notification to be broadcast on multiple devices.

    public static void ConfigureNotificationMirroring(NotificationMirroring value)public static void ConfigureNotificationMirroring(NotificationMirroring value)Public Static Function ConfigureNotificationMirroring(value As NotificationMirroring) As voidpublic static void ConfigureNotificationMirroring(NotificationMirroring value)

    Parameters

  • CreateToastNotifier()
    CreateToastNotifier()
    CreateToastNotifier()
    CreateToastNotifier()

    Creates and initializes a new instance of the ToastNotification, bound to the calling application, that lets you raise a toast notification to that app.

    public static ToastNotifier CreateToastNotifier()public static ToastNotifier CreateToastNotifier()Public Static Function CreateToastNotifier() As ToastNotifierpublic static ToastNotifier CreateToastNotifier()

    Returns

    Remarks

    Do not use this overload when creating a toast notifier for a desktop app. Use CreateToastNotifier(String) to supply the required AppUserModelID.

    If your app uses a background voice-over-Internet protocol (VOIP) agent, it must specify the app ID to show a toast. Use the CreateToastNotifier(String) method overload.

    Examples

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

    Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.

    public static ToastNotifier CreateToastNotifier(String applicationId)public static ToastNotifier CreateToastNotifier(String applicationId)Public Static Function CreateToastNotifier(applicationId As String) As ToastNotifierpublic static ToastNotifier CreateToastNotifier(String applicationId)

    Parameters

    • applicationId
      System.String
      System.String
      System.String
      System.String

      The unique ID of the app.

      Note

      You can't send a toast notification to a secondary tile, so this must be the ID of an app tile.

    Returns

    Remarks

    The app identified by applicationId must belong to the same package as the caller.

    Use this form of the method if your app uses a background voice-over-Internet protocol (VOIP) agent, to specify the app ID required to show a toast in that case.

    Sending toast notifications from desktop apps

    Generally, sending a toast notification from a desktop app is the same as sending it from a Windows Store app. However, you should be aware of these differences and requirements:

    • For a desktop app to display a toast, the app must have a shortcut on the Start screen.
    • The shortcut must have an AppUserModelID.
    • Desktop apps cannot schedule a toast.

    For more information, see these topics:

  • GetDefault()
    GetDefault()
    GetDefault()
    GetDefault()

    Prerelease. Gets a toast notification manager for the current user.

    public static ToastNotificationManagerForUser GetDefault()public static ToastNotificationManagerForUser GetDefault()Public Static Function GetDefault() As ToastNotificationManagerForUserpublic static ToastNotificationManagerForUser GetDefault()

    Returns

  • GetForUser(User)
    GetForUser(User)
    GetForUser(User)
    GetForUser(User)

    Gets a toast notification manager for the specified user.

    public static ToastNotificationManagerForUser GetForUser(User user)public static ToastNotificationManagerForUser GetForUser(User user)Public Static Function GetForUser(user As User) As ToastNotificationManagerForUserpublic static ToastNotificationManagerForUser GetForUser(User user)

    Parameters

    Returns

  • GetTemplateContent(ToastTemplateType)
    GetTemplateContent(ToastTemplateType)
    GetTemplateContent(ToastTemplateType)
    GetTemplateContent(ToastTemplateType)

    Gets the XML content of one of the predefined toast templates so that you can customize it for use in your notification.

    public static XmlDocument GetTemplateContent(ToastTemplateType type)public static XmlDocument GetTemplateContent(ToastTemplateType type)Public Static Function GetTemplateContent(type As ToastTemplateType) As XmlDocumentpublic static XmlDocument GetTemplateContent(ToastTemplateType type)

    Parameters

    Returns

    Remarks

    Instead of creating the full XML payload yourself, you can get a template and then use Document Object Model (DOM) manipulation functions to customize the part of the content that you want to change. You package this XML in a ToastNotification and send it to the tile through the ToastNotifier that you create through the other methods of this class.

    See tile schema for an explanation of tile elements and attributes.

    Examples

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

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
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.UI.Notifications.dll