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); } } }