Created
January 18, 2017 11:45
-
-
Save lavn0/6e4eacb836e34dea140ee7a27f2209db to your computer and use it in GitHub Desktop.
トースト通知のサンプル実装(Windows8.1以降)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Windows.UI.Notifications; | |
namespace ToastTest | |
{ | |
public static class Toast | |
{ | |
private static readonly ToastNotifier toastNotifier; | |
private static ToastNotification toastNotification; | |
static Toast() | |
{ | |
toastNotifier = ToastNotificationManager.CreateToastNotifier("test"); | |
} | |
/// <summary>トースト通知を行います</summary> | |
/// <param name="text">通知する内容</param> | |
public static void Notify(string text) | |
{ | |
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); | |
var toastTextElements = toastXml.GetElementsByTagName("text"); | |
toastTextElements[0].AppendChild(toastXml.CreateTextNode(text)); | |
if (toastNotification != null) | |
{ | |
toastNotifier.Hide(toastNotification); | |
} | |
toastNotification = new ToastNotification(toastXml); | |
toastNotification.Failed += (ToastNotification n, ToastFailedEventArgs a) => Debug.WriteLine(a.ErrorCode); | |
toastNotifier.Show(toastNotification); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment