我的目標是Windows 10,最新的操作系統版本。我從Microsoft自適應吐司示例中複製/粘貼了一些東西 - 包括路徑。這是我的代碼:UWP吐司工作,但圖像(AdaptiveImage,ToastGenericHeroImage,ToastGenericAppLogo)不顯示
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);
}
吐司顯示,但圖像沒有。任何人有想法?
編輯:作爲@AVK建議,我決定使用XML而不是給它一個鏡頭;不幸的是,我得到了同樣的行爲 - 敬酒節目,但沒有圖像。這裏是我的代碼(但無可否認,我知道即使有關XML的少,所以這個代碼可能是錯誤的-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);
當你創建實際的XML時做這個工作嗎? – AVK
@AVK很好的問題;我會檢查出 – codeMonkey
@AVK用XML示例更新 – codeMonkey