ToastNotificationManager
ToastNotificationManager
ToastNotificationManager
ToastNotificationManager
ToastNotificationManager
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 ToastNotificationManager
static struct winrt::Windows::UI::Notifications::ToastNotificationManager
public static class ToastNotificationManager
Public Shared Class ToastNotificationManager
// This class does not provide a public constructor.
- 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 UWP 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:
- How to enable desktop toast notifications through an AppUserModelID
- Quickstart: Sending a toast notification from the desktop
Version history
Windows version | SDK version | Value added |
---|---|---|
1607 | 14393 | ConfigureNotificationMirroring |
1607 | 14393 | GetForUser |
1703 | 15063 | GetDefault |
Properties
History History History History History |
Gets the ToastNotificationHistory object. |
Methods
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
Feedback
Loading feedback...