Toast notification isn't working?

2019-02-25 16:21发布

I'm following several examples to do a toast notification when I click a button in my app. I stepped through the following example: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx

I'm not getting any errors but when I run the application I don't get the toast notification. I have created a snippet here: http://codepaste.net/btkzeg

ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));

XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");

((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/oil.png");
((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "oil graphic");

IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");

((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

ToastNotification toast = new ToastNotification(toastXml);

ToastNotificationManager.CreateToastNotifier().Show(toast);

If you have suggestions please let me know.

3条回答
【Aperson】
2楼-- · 2019-02-25 17:00

in Package.appxmanifest file, ApplicationUI/Toast capable should be Yes in order to Show our toast notifications.

查看更多
男人必须洒脱
3楼-- · 2019-02-25 17:02

Also, make sure that you have "toast capable" set in the manifest (Package.appxmanifest).

查看更多
beautiful°
4楼-- · 2019-02-25 17:19

I figured out the issue. I needed to set my app manifest to Toast Capable. I also noticed it doesn't work in simulator mode... But in Local Machine mode it worked.

查看更多
登录 后发表回答