Skip to content

Instantly share code, notes, and snippets.

@lavn0
Created January 18, 2017 11:45
Show Gist options
  • Save lavn0/6e4eacb836e34dea140ee7a27f2209db to your computer and use it in GitHub Desktop.
Save lavn0/6e4eacb836e34dea140ee7a27f2209db to your computer and use it in GitHub Desktop.
トースト通知のサンプル実装(Windows8.1以降)
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