locked
Toast Notification not displaying RRS feed

  • Question

  • I wanted to test a simple toast notification but its not working..
    what am i doing wrong?

            private void Button_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("Texter!");
                toastTextElements[0].AppendChild(toastXml.CreateTextNode("Toaster!"));


                ToastNotification toast = new ToastNotification(toastXml);

                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }

    Tuesday, June 19, 2012 8:05 AM

Answers

  • Had to change your code slightly to make it work:( Notice the GetElementsByTagName function parameter - i.e. text- and the two nodes we have to setup.

    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("Toast Title"));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode("Toast Description"));
    
    
    ToastNotification toast = new ToastNotification(toastXml);
    toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(30);
    toast.Failed += (o, args) => {
        var message = args.ErrorCode;
    };
    
    ToastNotificationManager.CreateToastNotifier().Show(toast);

    Another thing I have to change was to set the package manifest to make the application toast-capable:

    The Failed event handler was just added to see what the problem was. Also the expiration was just to extend the expiration time for the toast.

    Let me know how it works out for you.

    Good luck.


    Can Bilgin
    Blog CompuSight

    • Proposed as answer by Can Bilgin Tuesday, June 19, 2012 1:17 PM
    • Marked as answer by singh029 Wednesday, June 20, 2012 7:48 PM
    Tuesday, June 19, 2012 8:58 AM

All replies

  • Had to change your code slightly to make it work:( Notice the GetElementsByTagName function parameter - i.e. text- and the two nodes we have to setup.

    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    
    toastTextElements[0].AppendChild(toastXml.CreateTextNode("Toast Title"));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode("Toast Description"));
    
    
    ToastNotification toast = new ToastNotification(toastXml);
    toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(30);
    toast.Failed += (o, args) => {
        var message = args.ErrorCode;
    };
    
    ToastNotificationManager.CreateToastNotifier().Show(toast);

    Another thing I have to change was to set the package manifest to make the application toast-capable:

    The Failed event handler was just added to see what the problem was. Also the expiration was just to extend the expiration time for the toast.

    Let me know how it works out for you.

    Good luck.


    Can Bilgin
    Blog CompuSight

    • Proposed as answer by Can Bilgin Tuesday, June 19, 2012 1:17 PM
    • Marked as answer by singh029 Wednesday, June 20, 2012 7:48 PM
    Tuesday, June 19, 2012 8:58 AM
  • OH WOW. i would never have seen the "toast capable" option. I couldn't even find that in the documentation for toast notifications or the samples or the quick start guide microsoft made.

    Anyways, it works great but the only problem is that it doesn't want to work on the simulator (tablet).
    Is there another configuration I must set up to see notifications on the simulator?

    Tuesday, June 19, 2012 10:06 AM
  • i don't think it is possible to receive notifications on the simulator.

    Can Bilgin
    Blog CompuSight

    Tuesday, June 19, 2012 10:22 AM
  • If your question has been answered, please mark the appropriate post as answer so other community members with a similar question can find help faster.

    Can Bilgin
    Blog CompuSight

    Wednesday, June 20, 2012 3:43 PM
  • why toast notifications is not working in simulator?

    Dhruv

    Friday, July 13, 2012 9:18 AM
  • I'm having the same problem here. Notification won't show on my simulator. Is there anything I can do?
    Monday, December 24, 2012 8:27 AM