Language

ToastNotificationManager クラス

定義

トースト通知を発生させるために使用する ToastNotifier オブジェクトを作成します。 このクラスでは、システム提供のトースト テンプレートの XML コンテンツへのアクセスも提供されるため、通知で使用するためにそのコンテンツをカスタマイズできます。

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
継承
Object Platform::Object IInspectable ToastNotificationManager
属性

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 で導入)

例

次の例では、 GetTemplateContent メソッドや 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);

注釈

デスクトップ アプリからのトースト通知の送信

一般に、デスクトップ アプリからのトースト通知の送信は、UWP アプリからの送信と同じです。 ただし、次の違いと要件に注意する必要があります。

  • デスクトップ アプリでトーストを表示するには、スタート画面にショートカットが必要です。
  • ショートカットには AppUserModelID が必要です。
  • デスクトップ アプリではトーストをスケジュールできません。

詳細については、次のトピックを参照してください。

バージョン履歴

Windows のバージョン SDK のバージョン 付加価値
1607 14393 ConfigureNotificationMirroring
1607 14393 GetForUser
1703 15063 GetDefault

プロパティ

Name 説明
History

ToastNotificationHistory オブジェクトを取得します。

メソッド

Name 説明
ConfigureNotificationMirroring(NotificationMirroring)

通知ミラーリングを許可するかどうかを指定します。 通知ミラーリングを使用すると、複数のデバイスで通知をブロードキャストできます。

CreateToastNotifier()

呼び出し元アプリケーションにバインドされた ToastNotifier の新しいインスタンスを作成して初期化します。これにより、そのアプリにトースト通知を生成できます。

CreateToastNotifier(String)

ToastNotifier の新しいインスタンスを作成して初期化します。このインスタンスは、指定したアプリ (通常は同じパッケージ内の別のアプリ) にバインドされます。

GetDefault()

現在のユーザーのトースト通知マネージャーを取得します。

GetForUser(User)

指定したユーザーのトースト通知マネージャーを取得します。

GetTemplateContent(ToastTemplateType)

通知で使用できるようにカスタマイズできるように、定義済みのトースト テンプレートの 1 つの XML コンテンツを取得します。

適用対象

関連項目