PG.Lib

アプリ開発関連とかガジェット関連とか

トースト通知をサクっと表示する

Windows8系だと画面の右上に出てくるアレ。

WindowsPhoneだと通知センターに残るアレ。

ダイアログ出すまでもないメッセージを表示するのに便利っぽいけど、通知センターに残ったりしてみっともないケースもあるので、使い方には注意が必要かな?

 

Using

using Windows.UI.Notifications;

 

Notify!

public static void ShowToast(string message)
{
    var toastXmlString = string.Format("<toast><visual version='1'><binding template='ToastText01'><text id='1'>{0}</text></binding></visual></toast>", message);
    var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
    xmlDoc.LoadXml(toastXmlString);
    var toast = new ToastNotification(xmlDoc);
    ToastNotificationManager.CreateToastNotifier().Show(toast);
}

 

表示フォーマットは色々あるので、凝った事するならもうちょっと掘り下げないとね。

参考:MSDN トースト テンプレート カタログ

 


追記

Package.appmanifest に設定が必要だった!!

アプリケーションタブ → 通知 → トースト対応 を 「はい」 にするのを忘れずに!!(忘れてたw)