zhaojs
2023-09-27 74098f1401afe40f961d1d167bb18dd0a71c4d59
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
37
38
39
40
41
42
using System;
using System.IO;
using System.Xml;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
 
namespace DesktopMessage
{
    class Program
    {
        static void Main(string[] args)
        {
            GenerateToast("12311", "", "123", "456", "aaa");
            Console.ReadLine();
        }
 
        public static void GenerateToast(string appid, string imageFullPath, string h1, string h2, string p1)
        {
 
            var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
 
            var textNodes = template.GetElementsByTagName("text");
 
            textNodes[0].AppendChild(template.CreateTextNode(h1));
            textNodes[1].AppendChild(template.CreateTextNode(h2));
            textNodes[2].AppendChild(template.CreateTextNode(p1));
 
            if (File.Exists(imageFullPath))
            {
                Windows.Data.Xml.Dom.XmlNodeList toastImageElements = template.GetElementsByTagName("image");
                ((Windows.Data.Xml.Dom.XmlElement)toastImageElements[0]).SetAttribute("src", imageFullPath);
            }
            IXmlNode toastNode = template.SelectSingleNode("/toast");
            ((Windows.Data.Xml.Dom.XmlElement)toastNode).SetAttribute("duration", "long");
 
            var notifier = ToastNotificationManager.CreateToastNotifier(appid);
            var notification = new ToastNotification(template);
 
            notifier.Show(notification);
        }
    }
}