UWP Toast 可以工作,但图像(AdaptiveImage、ToastGenericHeroImage、ToastGenericAppLogo)不显示

cod*_*key 4 c# xml windows-10 uwp visual-studio-2017

我的目标是 Windows 10,最新的操作系统版本。我从 Microsoft 自适应 Toast 示例中复制/粘贴了一些内容 - 包括路径。这是我的代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

显示 toast,但不显示图像。有人有主意吗?


编辑:正如 @AVK 建议的那样,我决定尝试使用 XML;不幸的是我得到了同样的行为——吐司显示,但没有图像。这是我的代码(尽管我承认我对 XML 知之甚少,所以这段代码可能是错误的):

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);
Run Code Online (Sandbox Code Playgroud)

小智 6

Http 图像仅在清单中具有 Internet 功能的 Desktop Bridge 应用程序中受支持。经典 Win32 应用程序不支持 http 图像;您必须将图像下载到本地应用程序数据并在本地引用它。