はじめに
UWP コンソールC#アプリから指定の時間にトースト通知させようと考え、
UWPアプリからトースト通知する方法を調べ、実装しました。
環境
Windows 11 Pro
Visual Studio 2017 Express
設定
コンソールアプリからWinRTのトースト通知を利用するためにNuGetからMicrosoft.UWP.Notificationsをインストールします。
プログラムコード
static void Main(string[] args)
{
var type = ToastTemplateType.ToastText01;
var content = ToastNotificationManager.GetTemplateContent(type);
var text = content.GetElementsByTagName("text").First();
text.AppendChild(content.CreateTextNode("一休み"));
var notifier = ToastNotificationManager.CreateToastNotifier("通知");
notifier.Show(new ToastNotification(content));
}
結果
うまくでました。
参照
↧