C# Windows 10 Toast 通知 [英] C# Windows 10 Toast Notifications

查看:107
本文介绍了C# Windows 10 Toast 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在计时器超时后显示 Toast 通知.该通知适用于我的其中一台 PC,但另一台无法显示.我调试的时候没有报错.我还尝试在设置">通知"中设置一些内容,但在允许/不允许显示通知的应用列表中我看不到我的应用.

I'm trying to display a toast notification after a timer run out of time. The notification works on one of my PC's but the other one won't display it. I get no error when I'm debugging it. I also tried to set something in the Settings>Notifications but in the list of apps which are allowed/not allowed to display notifications I can't see my application.

这是我的通知类:

    class NewToastNotification
   {
      public NewToastNotification(string text)
      {
         string Toast = String.Format("<toast>"+
                                          "<visual>+" +
                                                "<binding template=\"ToastImageAndText04\">" +
                                                    "<text id = \"1\" >Toast Test </text>+" +
                                                    "<text id = \"2\" >{0}</text>+" +
                                                    "<text id = \"2\" >{1}</text>+" +
                                                "</binding>+" +
                                          "</visual>+" +
                                     "</toast>", text, DateTime.Now);

         var tileXml = new Windows.Data.Xml.Dom.XmlDocument();
         tileXml.LoadXml(Toast);
         var toast = new ToastNotification(tileXml);
         ToastNotificationManager.CreateToastNotifier("1").Show(toast);
      }
   }

推荐答案

使用

ToastNotificationManager.CreateToastNotifier().Show(toast);

代替

ToastNotificationManager.CreateToastNotifier("1").Show(toast);

这篇关于C# Windows 10 Toast 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆