我正在使用Toast通知开发
Windows 8 metro风格的应用程序. (C#xaml组合)
我查看了MS metro样式示例代码,并尝试将其应用到我的项目中,
看起来我使用的代码完全相同,但我不知道为什么它不工作..
我查看了MS metro样式示例代码,并尝试将其应用到我的项目中,
看起来我使用的代码完全相同,但我不知道为什么它不工作..
(没有错误,它构建成功但只是不起作用.)
我想要做的很简单:
有一个按钮.
当button_click事件发生时,我想弹出一个Toast通知.
这就是我做的:
namespace Application1 { public sealed partial class BlankPage : Page { public BlankPage() { this.InitializeComponent(); Scenario2Init(); } void Scenario2Init() { toastTest.Click += (sender,e) => { ToastAlarm(true); }; } void ToastAlarm(bool loopAudio) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); // Toasts can optionally be set to long duration by adding the 'duration' attribute IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration","long"); // This XmlNodeList will have two items since the template we are using has two text fields. XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Long Duration Toast")); XmlElement audioElement = toastXml.CreateElement("audio"); if (loopAudio) { // Long-duration Toasts can optionally loop audio using the 'loop' attribute audioElement.SetAttribute("src","ms-winsoundevent:Notification.Looping.Alarm"); audioElement.SetAttribute("loop","true"); stringElements.Item(1).AppendChild(toastXml.CreateTextNode("Looping audio")); } else { audioElement.SetAttribute("src","ms-winsoundevent:Notification.IM"); } toastNode.AppendChild(audioElement); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); //Scenario2OutputText.Text = toastXml.GetXml(); } } }
如果我单击按钮,则没有任何反应.为什么?
解决方法
你的代码对我来说是正确的;我现在没有Win8和我在一起所以我无法测试它.但是,如果您在VS中的“Toast Capable”字段中启用了Toast,则可能需要检查应用程序的清单.希望这可以帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。