Share via


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 notificationManager = ToastNotificationManager;
var template = ToastTemplateType.ToastImageAndText01;
var toastXml = notificationManager.GetTemplateContent(template);

var images = toastXml.GetElementsByTagName("image");
images[0].SetAttribute("src", "images/toastImageAndText.png");

var textNodes = toastXml.GetElementsByTagName("text");
textNodes[0].AppendChild(toastXml.CreateTextNode("Text input 1"));

var toast = new ToastNotification(toastXml);
notificationManager.CreateToastNotifier().Show(toast);

The following example shows the use of the GetScheduledToastNotifications and RemoveFromSchedule methods.

var notifier = ToastNotificationManager.CreateToastNotifier();
var scheduled = notifier.GetScheduledToastNotifications();

for (int i = 0; i < scheduled.Count; i++) {
    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