[英]Windows 10 toast notification icon referencing
我决定扔掉“老派”windows baloon 通知并使用新的windows 10 本地toast 通知。
现在,我正在努力为 toast 通知引用一个图标。 根据 Microsocft 文档( 此处和此处),我应该能够添加这样的通知图标:
// Get a toast XML template
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Create image element
var image = toastXml.CreateElement("image");
image.SetAttribute("src", "https://picsum.photos/48?image=883");
image.SetAttribute("placement", "appLogoOverride");
toastXml.DocumentElement.AppendChild(image);
相反,会出现一个默认的应用程序图标:
实际工作的唯一方法是使用图像的绝对路径:
"file:///" + Path.GetFullPath("../../Assets/myicon.png");
但是,这不能满足我的需求,因为我需要引用资源图标或来自网络的图标。
因此我的问题:
https://picsum.photos/48?image=883
)?.svg
图像吗?如何在 Toast 通知中正确引用网络图像 ( https://picsum.photos/48?image=883 )?
我们可以通过UWP Community Toolkit Notifications nuget 包轻松实现 toast 通知。 如果要为AppLogoOverride
引用 Web 图像,请创建AppLogoOverride
实例并设置Source
属性,如下所示。
例如:
var toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Matt sent you a friend request"
},
new AdaptiveText()
{
Text = "Hey, wanna dress up as wizards and ride around on our hoverboards together?"
}
},
AppLogoOverride = new ToastGenericAppLogo()
{
Source = "https://unsplash.it/64?image=1005",
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
},
Actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("Accept", "action=acceptFriendRequest&userId=49183")
{
ActivationType = ToastActivationType.Background
},
new ToastButton("Decline", "action=declineFriendRequest&userId=49183")
{
ActivationType = ToastActivationType.Background
}
}
},
Launch = "action=viewFriendRequest&userId=49183"
};
// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());
// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
如何正确引用资源图标?
如果要引用资源图标和资产文件夹中的图标资源,可以参考以下代码。
new AdaptiveImage()
{
Source = "Assets/Apps/Food/RestaurantMap.jpg"
}
Toast 通知图标中允许使用哪些图像类型? 我可以参考,例如 .svg 图像吗?
对于我的测试,可用于 Toast 通知的png 、 jpg和svg图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.