Dela via


ToastNotificationManager.CreateToastNotifier Method

Definition

Overloads

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)

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

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();
/// [Windows.Foundation.Metadata.Overload("CreateToastNotifier")]
 static ToastNotifier CreateToastNotifier();
[Windows.Foundation.Metadata.Overload("CreateToastNotifier")]
public static ToastNotifier CreateToastNotifier();
function createToastNotifier()
Public Shared Function CreateToastNotifier () As ToastNotifier

Returns

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

Attributes

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

Applies to

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);
/// [Windows.Foundation.Metadata.Overload("CreateToastNotifierWithId")]
 static ToastNotifier CreateToastNotifier(winrt::hstring const& applicationId);
[Windows.Foundation.Metadata.Overload("CreateToastNotifierWithId")]
public static ToastNotifier CreateToastNotifier(string applicationId);
function createToastNotifier(applicationId)
Public Shared Function CreateToastNotifier (applicationId As String) As ToastNotifier

Parameters

applicationId
String

Platform::String

winrt::hstring

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.

Attributes

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

Applies to