ToastNotificationManager class

Applies to Windows and Windows Phone

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


var toastNotificationManager = Windows.UI.Notifications.ToastNotificationManager;

Attributes

[DualApiPartition()]
[Threading(MTA)]
[Version(0x06020000)]

Members

The ToastNotificationManager class has these types of members:

Methods

The ToastNotificationManager class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
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.
CreateToastNotifier(String) Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.
GetTemplateContent Gets the XML content of one of the predefined toast templates so that you can customize it for use in your notification.

 

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

Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.UI.Notifications
Windows::UI::Notifications [C++]

Metadata

Windows.winmd

See also

Toast notifications sample
Sending toast notifications from desktop apps sample
Toast XML schema
Toast notification overview
Quickstart: Sending a toast notification
Quickstart: Sending a toast push notification
Quickstart: Sending a toast notification from the desktop
Guidelines and checklist for toast notifications
How to handle activation from a toast notification
How to opt in for toast notifications
How to schedule a toast notification
How to enable desktop toast notifications through an AppUserModelID
The toast template catalog
Toast audio options

 

 

Show:
© 2014 Microsoft. All rights reserved.