codeMonkey
codeMonkey

Reputation: 4815

UWP Toast works, but images (AdaptiveImage, ToastGenericHeroImage, ToastGenericAppLogo) not displaying

I am targeting Windows 10, latest OS build. I copy/pasted some stuff from the Microsoft adaptive toast examples--including the paths. Here's my code:

public void CreateToast(ToastViewModel model)
{
    ToastContent content = new ToastContent()
    {
        Launch = "app-defined-string",

        Visual = new ToastVisual()
        {
            BindingGeneric = new ToastBindingGeneric()
            {
                Children =
                {
                    new AdaptiveText()
                    {
                        Text = "Photo Share"
                    },

                    new AdaptiveText()
                    {
                        Text = "Andrew sent you a picture"
                    },

                    new AdaptiveText()
                    {
                        Text = "See it in full size!"
                    },

                    new AdaptiveImage()
                    {
                        Source = "https://unsplash.it/360/180?image=1043"
                    }
                },
                HeroImage = new ToastGenericHeroImage()
                {
                    Source = "https://unsplash.it/360/180?image=1043"
                },
                AppLogoOverride = new ToastGenericAppLogo()
                {
                    Source = "https://unsplash.it/64?image=883",
                    HintCrop = ToastGenericAppLogoCrop.Circle
                }
            }
        }
    };

    var toast = new ToastNotification(content.GetXml());
    toast.Failed += (o, args) =>
    {
        var message = args.ErrorCode;
    };

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

The toast displays, but the images do not. Anyone have an idea?


EDIT: As @AVK suggested I decided to give it a shot using XML instead; unfortunately I get the same behavior -- toast shows, but no images. Here's my code for that (though admittedly I know even less about XML, so this code could be wrong-er):

var template = ToastTemplateType.ToastImageAndText02;
var xml = ToastNotificationManager.GetTemplateContent(template);
var elements = xml.GetElementsByTagName("text");
var text = xml.CreateTextNode(model.Title);
elements[0].AppendChild(text);
var images = xml.GetElementsByTagName("image");
var srcAttribute = xml.CreateAttribute("src");
srcAttribute.Value = "https://unsplash.it/64?image=883";
images[0].Attributes.SetNamedItem(srcAttribute);
var toast = new ToastNotification(xml);
ToastNotificationManager.CreateToastNotifier().Show(toast);

Upvotes: 4

Views: 2277

Answers (2)

Nuno Santos
Nuno Santos

Reputation: 61

Http images are only supported in Desktop Bridge apps that have the internet capability in their manifest. Classic Win32 apps do not support http images; you must download the image to your local app data and reference it locally.

Upvotes: 6

BlackGlory
BlackGlory

Reputation: 4031

This is a Windows 10 bug that causes Toast Notification for applications to not show images.

Run the troubleshooter for Windows apps could fix it.

Upvotes: 2

Related Questions