问题
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.
回答1:
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.
回答2:
Also, make sure that you have "toast capable" set in the manifest (Package.appxmanifest).
回答3:
in Package.appxmanifest file, ApplicationUI/Toast capable should be Yes in order to Show our toast notifications.
来源:https://stackoverflow.com/questions/12738428/toast-notification-isnt-working