通知 – windows 8 metro app – toast notification
发布时间:2020-12-14 05:54:08 所属栏目:Windows 来源:网络整理
导读:我正在使用Toast通知开发 Windows 8 metro风格的应用程序. (C#xaml组合) 我查看了MS metro样式示例代码,并尝试将其应用到我的项目中, 看起来我使用的代码完全相同,但我不知道为什么它不工作.. (没有错误,它构建成功但只是不起作用.) 我想要做的很简单: 有一
我正在使用Toast通知开发
Windows 8 metro风格的应用程序. (C#xaml组合)
我查看了MS metro样式示例代码,并尝试将其应用到我的项目中, 看起来我使用的代码完全相同,但我不知道为什么它不工作.. (没有错误,它构建成功但只是不起作用.) 我想要做的很简单: 有一个按钮. 这就是我做的: 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,则可能需要检查应用程序的清单.希望这可以帮助.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- winapi – 如何在Windows上检测已安装的Sun/Oracle JRE?
- 无法在Windows 10 Professional中安装自定义inf. Windows使
- 我可以在Windows Server 2003上运行.NET 4.0 Web应用程序吗
- windows-runtime – Winrt GridView虚拟化
- windows-server-2008 – 如何在Windows Server 2008 R2上列
- windows-phone-7 – 如何更改Panorama项目标题的字号?
- windows-server-2008 – 当我使用Powershell将用户添加到安
- .net – 获取“DialogResult只能在Window被创建之后被设置,
- windows – 当前的KMS是否需要旧版本的密钥?
- Windows 10 子系统 Ubuntu 中安装 FastAdmin