Search code examples
windows-phonewindows-phone-8.1

Show an image and a message in a toast notification on windows phone


I am trying to show an Image and text on windows phone. The text works but the image does not show up at all the docs on msdn says that it should though

here is my code ...

        ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

        XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
        toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
        XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
        ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/Square71x71Logo.scale-240.png");
        ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic");
        ToastNotification toast = new ToastNotification(toastXml);
        ToastNotificationManager.CreateToastNotifier().Show(toast);

Results

enter image description here

Expected Results

enter image description here

Image Square71x71Logo.scale-240.png

enter image description here


Solution

  • You cannot include an image in a toast on Windows Phone 8.1. The template will always be the app's logo then two text fields.

    This is documented near the top of the Toast Template Catalog documentation on MSDN.