ToastNotifier Класс

Определение

Создает всплывающее уведомление для конкретного приложения, к которому привязан ToastNotifier. Этот класс также позволяет планировать и удалять всплывающие уведомления.

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
Наследование
Object Platform::Object IInspectable ToastNotifier
Атрибуты

Требования к Windows

Семейство устройств
Windows 10 (появилось в 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (появилось в v1.0)

Примеры

В следующем примере показано, как создать и отправить всплывающее уведомление, содержащее текст и изображения, включая использование метода 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);

В следующем примере показано использование методов GetScheduledToastNotifications и 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]);
    }
}

Комментарии

При создании ToastNotifier привязывается к определенному приложению, поэтому методы этого класса влияют только на это приложение.

Журнал версий

Версия Windows Версия пакета SDK Добавленная стоимость
1703 15063 Update(NotificationData,String;String)
1703 15063 Update(NotificationData,String)
1809 17763 ScheduledToastNotificationShowing

Свойства

Setting

Возвращает значение, указывающее, есть ли приложение, пользователь или системный блок, который препятствует отображению всплывающего уведомления.

Методы

AddToSchedule(ScheduledToastNotification)

Добавляет scheduledToastNotification для последующего отображения в Windows.

Важно!

Этот метод поддерживается только в приложениях, использующих WinRT в качестве платформы приложений по умолчанию.

GetScheduledToastNotifications()

Возвращает коллекцию объектов ScheduledToastNotification , которые это приложение запланировало для отображения.

Важно!

Этот метод поддерживается только в приложениях, использующих WinRT в качестве платформы приложений по умолчанию.

Hide(ToastNotification)

Удаляет указанное всплывающее уведомление с экрана.

RemoveFromSchedule(ScheduledToastNotification)

Отменяет запланированное отображение указанного объекта ScheduledToastNotification.

Важно!

Этот метод поддерживается только в приложениях, использующих WinRT в качестве платформы приложений по умолчанию.

Show(ToastNotification)

Отображает указанное всплывающее уведомление.

Update(NotificationData, String)

Обновления существующее всплывающее уведомление с указанным тегом.

Update(NotificationData, String, String)

Обновления существующее всплывающее уведомление, имеющее указанный тег и принадлежащее указанной группе уведомлений.

События

ScheduledToastNotificationShowing

Происходит, когда система отображает запланированное всплывающее уведомление.

Применяется к

См. также раздел