Jaa


ToastNotifier Class

Definition

Raises a toast notification to the specific app to which the ToastNotifier is bound. This class also lets you schedule and remove toast notifications.

public ref class ToastNotifier sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class ToastNotifier final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ToastNotifier final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class ToastNotifier
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ToastNotifier
Public NotInheritable Class ToastNotifier
Inheritance
Object Platform::Object IInspectable ToastNotifier
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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

Remarks

When it is created, ToastNotifier is bound to a specific app, so the methods of this class affect only that app.

Version history

Windows version SDK version Value added
1703 15063 Update(NotificationData,String,String)
1703 15063 Update(NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

Properties

Setting

Gets a value that tells you whether there is an app, user, or system block that prevents the display of a toast notification.

Methods

AddToSchedule(ScheduledToastNotification)

Adds a ScheduledToastNotification for later display by Windows.

Important

This method is only supported in applications which use WinRT as their default application framework.

GetScheduledToastNotifications()

Gets the collection of ScheduledToastNotification objects that this app has scheduled for display.

Important

This method is only supported in applications which use WinRT as their default application framework.

Hide(ToastNotification)

Removes the specified toast notification from the screen.

RemoveFromSchedule(ScheduledToastNotification)

Cancels the scheduled display of a specified ScheduledToastNotification.

Important

This method is only supported in applications which use WinRT as their default application framework.

Show(ToastNotification)

Displays the specified toast notification.

Update(NotificationData, String, String)

Updates the existing toast notification that has the specified tag and belongs to the specified notification group.

Update(NotificationData, String)

Updates the existing toast notification that has the specified tag.

Events

ScheduledToastNotificationShowing

Occurs when the system shows the scheduled toast notification.

Applies to

See also