简体   繁体   中英

C# Windows 10 Toast Notifications

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.

This is my Notifications Class:

    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);
      }
   }

Use

ToastNotificationManager.CreateToastNotifier().Show(toast);

instead of

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM