加入收藏 | 设为首页 | 会员中心 | 我要投稿 武汉站长网 (https://www.027zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

通知 – windows 8 metro app – toast notification

发布时间:2021-02-03 19:38:37 所属栏目:系统 来源:网络整理
导读:我正在使用Toast通知开发 Windows 8 metro风格的应用程序. (C#xaml组合) 我查看了MS metro样式示例代码,并尝试将其应用到我的项目中, 看起来我使用的代码完全相同,但我不知道为什么它不工作.. (没有错误,它构建成功但只是不起作用.) 我想要做的很简单: 有

我正在使用Toast通知开发 Windows 8 metro风格的应用程序. (C#xaml组合)
我查看了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,则可能需要检查应用程序的清单.希望这可以帮助.

(编辑:武汉站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读