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)

後で Windows で表示できるように ScheduledToastNotification を追加します。

重要

このメソッドは、WinRT を既定のアプリケーション フレームワークとして使用するアプリケーションでのみサポートされます。

GetScheduledToastNotifications()

このアプリで表示がスケジュールされている ScheduledToastNotification オブジェクトのコレクションを取得します。

重要

このメソッドは、WinRT を既定のアプリケーション フレームワークとして使用するアプリケーションでのみサポートされます。

Hide(ToastNotification)

指定したトースト通知を画面から削除します。

RemoveFromSchedule(ScheduledToastNotification)

指定した ScheduledToastNotification のスケジュールされた表示を取り消します。

重要

このメソッドは、WinRT を既定のアプリケーション フレームワークとして使用するアプリケーションでのみサポートされます。

Show(ToastNotification)

指定したトースト通知を表示します。

Update(NotificationData, String)

指定したタグを持つ既存のトースト通知を更新します。

Update(NotificationData, String, String)

指定したタグを持ち、指定した通知グループに属する既存のトースト通知を更新します。

イベント

ScheduledToastNotificationShowing

スケジュールされたトースト通知がシステムに表示されるときに発生します。

適用対象

こちらもご覧ください