UWP Toast 工作正常,但图像(AdaptiveImage、ToastGenericHeroImage、ToastGenericAppLogo)不显示 [英] UWP Toast works, but images (AdaptiveImage, ToastGenericHeroImage, ToastGenericAppLogo) not displaying
问题描述
我的目标是 Windows 10,最新的操作系统版本.我从 Microsoft 自适应 Toast 示例中复制/粘贴了一些内容——包括路径.这是我的代码:
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?
正如@AVK 建议的那样,我决定改用 XML 试一试;不幸的是,我得到了相同的行为——吐司表演,但没有图像.这是我的代码(尽管我对 XML 了解得更少,所以这段代码可能是错误的):
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);
推荐答案
Http 图像仅在其清单中具有 Internet 功能的桌面桥应用程序中受支持.经典 Win32 应用程序不支持 http 图像;您必须将图像下载到本地应用数据并在本地引用.
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.
这篇关于UWP Toast 工作正常,但图像(AdaptiveImage、ToastGenericHeroImage、ToastGenericAppLogo)不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!