ToastNotifier Classe

Definizione

Genera una notifica di tipo avviso popup all'app specifica a cui è associato ToastNotifier. Questa classe consente anche di pianificare e rimuovere le notifiche di tipo avviso popup.

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
Ereditarietà
Object Platform::Object IInspectable ToastNotifier
Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 10 (è stato introdotto in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v1.0)

Esempio

Nell'esempio seguente viene illustrato come creare e inviare una notifica di tipo avviso popup che include testo e immagini, incluso l'uso del metodo Show .

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

Nell'esempio seguente viene illustrato l'uso dei metodi GetScheduledToastNotifications e RemoveFromSchedule .

var notifier = Notifications.ToastNotificationManager.createToastNotifier();
var scheduled = notifier.getScheduledToastNotifications();                    

for (var i = 0, len = scheduled.length; i < len; i++) {

    // The itemId value is the unique ScheduledTileNotification.Id assigned to the 
    // notification when it was created.
    if (scheduled[i].id === itemId) {
        notifier.removeFromSchedule(scheduled[i]);
    }
}

Commenti

Quando viene creato, ToastNotifier è associato a un'app specifica, quindi i metodi di questa classe influiscono solo sull'app.

Cronologia delle versioni

Versione di Windows Versione dell'SDK Valore aggiunto
1703 15063 Update(NotificationData,String,String)
1703 15063 Update(NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

Proprietà

Setting

Ottiene un valore che indica se è presente un blocco di sistema, un'app o un utente che impedisce la visualizzazione di una notifica di tipo avviso popup.

Metodi

AddToSchedule(ScheduledToastNotification)

Aggiunge un oggetto ScheduledToastNotification per la visualizzazione successiva da parte di Windows.

Importante

Questo metodo è supportato solo nelle applicazioni che usano WinRT come framework applicazione predefinito.

GetScheduledToastNotifications()

Ottiene l'insieme di oggetti ScheduledToastNotification pianificati per la visualizzazione dell'app.

Importante

Questo metodo è supportato solo nelle applicazioni che usano WinRT come framework applicazione predefinito.

Hide(ToastNotification)

Rimuove la notifica di tipo avviso popup specificata dalla schermata.

RemoveFromSchedule(ScheduledToastNotification)

Annulla la visualizzazione pianificata di un oggetto ScheduledToastNotification specificato.

Importante

Questo metodo è supportato solo nelle applicazioni che usano WinRT come framework applicazione predefinito.

Show(ToastNotification)

Visualizza la notifica di tipo avviso popup specificata.

Update(NotificationData, String)

Aggiornamenti la notifica di tipo avviso popup esistente con il tag specificato.

Update(NotificationData, String, String)

Aggiornamenti la notifica di tipo avviso popup esistente con il tag specificato e appartiene al gruppo di notifiche specificato.

Eventi

ScheduledToastNotificationShowing

Si verifica quando il sistema visualizza la notifica di tipo avviso popup pianificato.

Si applica a

Vedi anche