Raises a toast notification to the specific app that the notifier is bound to. This class also lets you schedule and remove toast notifications.
Syntax
var toastNotifier = createToastNotifier(); var toastNotifier = createToastNotifier(string);
Attributes
- DualApiPartitionAttribute()
- VersionAttribute(NTDDI_WIN8)
Members
The ToastNotifier class has these types of members:
Methods
The ToastNotifier class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| AddToSchedule | Adds a ScheduledToastNotification for later display by Windows. |
| GetScheduledToastNotifications | Gets the collection of ScheduledToastNotification objects that this app has scheduled for display. |
| Hide | Removes the specified toast notification from the screen. |
| RemoveFromSchedule | Cancels the scheduled display of a specified ScheduledToastNotification. |
| Show | Displays the specified toast notification. |
Properties
The ToastNotifier class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets a value that tells you whether there is an app, user, or system block that prevents the display of a toast notification. |
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 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 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]); } }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Namespace |
|
|
Metadata |
|
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
Build date: 12/4/2012