ToastNotificationManager Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée des objets ToastNotifier que vous utilisez pour déclencher des notifications toast. Cette classe fournit également l’accès au contenu XML des modèles toast fournis par le système afin que vous puissiez personnaliser ce contenu à utiliser dans vos notifications.
public ref class ToastNotificationManager abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
class ToastNotificationManager final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ToastNotificationManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
public static class ToastNotificationManager
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.MTA)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public static class ToastNotificationManager
Public Class ToastNotificationManager
- Héritage
- Attributs
Configuration requise pour Windows
| Configuration requise | Description |
|---|---|
| Famille d’appareils |
Windows 10 (introduit dans 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduit dans v1.0)
|
Exemples
L’exemple suivant montre comment créer et envoyer une notification toast qui inclut du texte et des images, y compris l’utilisation des méthodes GetTemplateContent et CreateToastNotifier .
// The GetTemplateContent method returns a Windows.Data.Xml.Dom.XmlDocument object
// that contains the toast notification XML content.
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
// You can use the methods from the XML document to specify the required elements for the toast.
var images = toastXml.GetElementsByTagName("image");
images[0].Attributes.Where( a => a.LocalName.ToString() == "src").First().NodeValue = "images/toastImageAndText.png";
var textNodes = toastXml.GetElementsByTagName("text");
for(var index = 0; index < textNodes.Count; index++)
{
var text = $"Text element {index}. ";
textNodes[index].AppendChild(toastXml.CreateTextNode(text));
};
// Create a toast notification from the XML, then create a ToastNotifier object
// to send the toast.
var toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
Remarques
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 est identique à celui 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 avoir un raccourci sur l’écran de démarrage.
- Le raccourci doit avoir un AppUserModelID.
- Les applications de bureau ne peuvent pas planifier un toast.
Pour plus d’informations, consultez les rubriques suivantes :
- Comment activer les notifications toast de bureau via un AppUserModelID
- Démarrage rapide : envoi d’une notification toast à partir du bureau
Historique des versions
| Version de Windows | Version du SDK | Valeur ajoutée |
|---|---|---|
| 1607 | 14393 | ConfigureNotificationMirroring |
| 1607 | 14393 | GetForUser |
| 1703 | 15063 | GetDefault |
Propriétés
| Nom | Description |
|---|---|
| History |
Obtient l’objet ToastNotificationHistory . |
Méthodes
| Nom | Description |
|---|---|
| ConfigureNotificationMirroring(NotificationMirroring) |
Spécifie si la mise en miroir de notifications est autorisée. La mise en miroir de notifications permet de diffuser une notification sur plusieurs appareils. |
| CreateToastNotifier() |
Crée et initialise une nouvelle instance de ToastNotifier, 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 ToastNotifier, liée à une application spécifiée, généralement une autre application dans le même package. |
| GetDefault() |
Obtient un gestionnaire de notifications toast pour l’utilisateur actuel. |
| GetForUser(User) |
Obtient un gestionnaire de notifications toast pour l’utilisateur spécifié. |
| GetTemplateContent(ToastTemplateType) |
Obtient le contenu XML de l’un des modèles toast prédéfinis afin de pouvoir le personnaliser pour une utilisation dans votre notification. |
S’applique à
Voir aussi
- Exemple de notifications toast
- Envoi de notifications toast à partir d’un exemple d’application de bureau
- Schéma XML toast
- Vue d’ensemble des notifications toast
- Démarrage rapide : Envoi d’une notification toast
- Démarrage rapide : Envoi d’une notification Push toast
- Démarrage rapide : envoi d’une notification toast à partir du bureau
- Recommandations et liste de contrôle pour les notifications toast
- Comment gérer l’activation à partir d’une notification toast
- Comment opter pour les notifications toast
- Guide pratique pour planifier une notification toast
- Comment activer les notifications toast de bureau via un AppUserModelID
- Catalogue de modèles toast
- Options audio toast