Share via


ToastNotificationManager.CreateToastNotifier Méthode

Définition

Surcharges

CreateToastNotifier()

Crée et initialise une nouvelle instance de ToastNotification, liée à l’application appelante, qui vous permet de déclencher une notification toast à cette application.

CreateToastNotifier(String)

Crée et initialise une nouvelle instance de ToastNotification, liée à une application spécifiée, généralement une autre application dans le même package.

CreateToastNotifier()

Crée et initialise une nouvelle instance de ToastNotification, liée à l’application appelante, qui vous permet de déclencher une notification toast à cette application.

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

Retours

Objet que vous allez utiliser pour envoyer la notification toast à l’application.

Attributs

Exemples

L’exemple suivant montre comment créer et envoyer une notification toast qui inclut du texte et des images, y compris l’utilisation de la méthode CreateToastNotifier.

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

Remarques

N’utilisez pas cette surcharge lors de la création d’un notificateur toast pour une application de bureau. Utilisez CreateToastNotifier(appID) pour fournir l’AppUserModelID requis.

Si votre application utilise un agent VOIP (Voix sur Internet) en arrière-plan, elle doit spécifier l’ID d’application pour afficher un toast. Utilisez la surcharge de méthode CreateToastNotifier(appID).

Voir aussi

S’applique à

CreateToastNotifier(String)

Crée et initialise une nouvelle instance de ToastNotification, liée à une application spécifiée, généralement une autre application dans le même 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

Paramètres

applicationId
String

Platform::String

winrt::hstring

ID unique de l’application.

Notes

Vous ne pouvez pas envoyer une notification toast à une vignette secondaire. Il doit donc s’agir de l’ID d’une vignette d’application.

Retours

Objet que vous allez utiliser pour envoyer la notification toast à la vignette.

Attributs

Remarques

L’application identifiée par applicationId doit appartenir au même package que l’appelant.

Utilisez cette forme de la méthode si votre application utilise un agent VOIP (Voix sur Internet) en arrière-plan, pour spécifier l’ID d’application requis pour afficher un toast dans ce cas.

Envoi de notifications toast à partir d’applications de bureau

En règle générale, l’envoi d’une notification toast à partir d’une application de bureau équivaut à l’envoi à partir d’une application UWP. Toutefois, vous devez connaître ces différences et exigences :

  • Pour qu’une application de bureau affiche un toast, l’application doit disposer d’un raccourci sur l’écran d’accueil.
  • Le raccourci doit avoir un AppUserModelID.
  • Les applications de bureau ne peuvent pas planifier de toast.

Pour plus d’informations, consultez les rubriques suivantes :

Voir aussi

S’applique à