-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToaster.cs
36 lines (30 loc) · 1.19 KB
/
Toaster.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace WinMediaPie
{
class Toaster
{
/// <summary>
/// Shows a Windows 10 ModernUI toast notification
/// </summary>
/// <param name="text">The content of the toast</param>
public static void Toast(string text = "")
{
try
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText03);
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode(text));
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = Constants.AppPaths.iconPngPath;
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier(Constants.APP_ID).Show(toast);
}
catch (Exception e)
{
Console.WriteLine($"Błąd podczas pokazywania powiadomienia: {e.ToString()}");
}
}
}
}