Toast​Notification​Manager Toast​Notification​Manager Toast​Notification​Manager Class

Definition

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.

public : static class ToastNotificationManagerpublic static class ToastNotificationManagerPublic Static Class ToastNotificationManager
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 the use of the GetTemplateContent 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);

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:

Properties

History History History

Gets the ToastNotificationHistory object.

public : static ToastNotificationHistory History { get; }public static ToastNotificationHistory History { get; }Public Static ReadOnly Property History As ToastNotificationHistory
Attributes

Methods

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 void
Parameters
Attributes
Additional features and requirements
Device family
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v3)

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 ToastNotifier
Returns

The object you will use to send the toast notification to the app.

Attributes

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

Remarks

Do not use this overload when creating a toast notifier for a desktop app. Use CreateToastNotifier(appID) 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(appID) method overload.

See Also

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(PlatForm::String applicationId)public static ToastNotifier CreateToastNotifier(String applicationId)Public Static Function CreateToastNotifier(applicationId As String) As ToastNotifier
Parameters
applicationId
PlatForm::String String 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

The object you will use to send the toast notification to the tile.

Attributes

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:

See Also

GetDefault() GetDefault() GetDefault()

Gets a toast notification manager for the current user.

public : static ToastNotificationManagerForUser GetDefault()public static ToastNotificationManagerForUser GetDefault()Public Static Function GetDefault() As ToastNotificationManagerForUser
Returns
Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

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 ToastNotificationManagerForUser
Parameters
user
User User User

The user who will receive the toast notifications.

Returns

A object for creating toast notifications for the specified user.

Attributes
Additional features and requirements
Device family
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v3)

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 XmlDocument
Parameters
type
ToastTemplateType ToastTemplateType ToastTemplateType

One of the system-provided toast templates.

Returns

The object that contains the template XML.

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

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.

See Also

See Also