ToastNotificationManager.CreateToastNotifier ToastNotificationManager.CreateToastNotifier ToastNotificationManager.CreateToastNotifier ToastNotificationManager.CreateToastNotifier ToastNotificationManager.CreateToastNotifier Method

Definition

Overloads

CreateToastNotifier() CreateToastNotifier() CreateToastNotifier() CreateToastNotifier() 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) CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String)

Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.

CreateToastNotifier() CreateToastNotifier() CreateToastNotifier() CreateToastNotifier() 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.

public : static ToastNotifier CreateToastNotifier()
static ToastNotifier CreateToastNotifier() const;
public static ToastNotifier CreateToastNotifier()
Public Shared Function CreateToastNotifier() As ToastNotifier
var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.createToastNotifier();

Returns

The object you will use to send the toast notification to the app.

Examples

The following example shows how to create and send a toast notification that includes text and images, including the use of the CreateToastNotifier 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(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

Do not use this overload when creating a toast notifier for a desktop app. Use CreateToastNotifier(appID) to supply the required AppUserModelID.

If your app uses a background voice-over-Internet protocol (VOIP) agent, it must specify the app ID to show a toast. Use the CreateToastNotifier(appID) method overload.

See also

CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String) CreateToastNotifier(String)

Creates and initializes a new instance of the ToastNotification, bound to a specified app, usually another app in the same package.

public : static ToastNotifier CreateToastNotifier(Platform::String applicationId)
static ToastNotifier CreateToastNotifier(winrt::hstring applicationId) const;
public static ToastNotifier CreateToastNotifier(String applicationId)
Public Shared Function CreateToastNotifier(applicationId As String) As ToastNotifier
var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.createToastNotifier(applicationId);

Parameters

applicationId
String String String

The unique ID of the app.

Note

You can't send a toast notification to a secondary tile, so this must be the ID of an app tile.

Returns

The object you will use to send the toast notification to the tile.

Remarks

The app identified by applicationId must belong to the same package as the caller.

Use this form of the method if your app uses a background voice-over-Internet protocol (VOIP) agent, to specify the app ID required to show a toast in that case.

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:

See also