ToastNotifier Classe

Definição

Gera uma notificação do sistema para o aplicativo específico ao qual o ToastNotifier está associado. Essa classe também permite agendar e remover notificações do sistema.

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
Herança
Object Platform::Object IInspectable ToastNotifier
Atributos

Requisitos do Windows

Família de dispositivos
Windows 10 (introduzida na 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduzida na v1.0)

Exemplos

O exemplo a seguir mostra como criar e enviar uma notificação do sistema que inclui texto e imagens, incluindo o uso do método 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);

O exemplo a seguir mostra o uso dos métodos 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]);
    }
}

Comentários

Quando ele é criado, ToastNotifier é associado a um aplicativo específico, portanto, os métodos dessa classe afetam apenas esse aplicativo.

Histórico de versão

Versão do Windows Versão do SDK Valor adicionado
1703 15063 Update(NotificationData,String,String)
1703 15063 Update(NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

Propriedades

Setting

Obtém um valor que informa se há um aplicativo, um usuário ou um bloco do sistema que impede a exibição de uma notificação do sistema.

Métodos

AddToSchedule(ScheduledToastNotification)

Adiciona um ScheduledToastNotification para exibição posterior pelo Windows.

Importante

Esse método só tem suporte em aplicativos que usam o WinRT como sua estrutura de aplicativo padrão.

GetScheduledToastNotifications()

Obtém a coleção de objetos ScheduledToastNotification que este aplicativo agendou para exibição.

Importante

Esse método só tem suporte em aplicativos que usam o WinRT como sua estrutura de aplicativo padrão.

Hide(ToastNotification)

Remove a notificação do sistema especificada da tela.

RemoveFromSchedule(ScheduledToastNotification)

Cancela a exibição agendada de um ScheduledToastNotification especificado.

Importante

Esse método só tem suporte em aplicativos que usam o WinRT como sua estrutura de aplicativo padrão.

Show(ToastNotification)

Exibe a notificação do sistema especificada.

Update(NotificationData, String)

Atualizações a notificação do sistema existente que tem a marca especificada.

Update(NotificationData, String, String)

Atualizações a notificação do sistema existente que tem a marca especificada e pertence ao grupo de notificação especificado.

Eventos

ScheduledToastNotificationShowing

Ocorre quando o sistema mostra a notificação agendada do sistema.

Aplica-se a

Confira também