c# - Windows 10 toast 通知图标引用
问题描述
我决定抛弃“老派”的 Windows 气球通知并使用新的 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
在我的 toast 通知中正确引用网络图像 ( )? - 如何正确引用资源图标?
- Toast 通知图标中允许使用哪些图像类型?我可以参考,例如
.svg
图像吗?
解决方案
如何在我的 toast 通知中正确引用网络图像 ( https://picsum.photos/48?image=883 )?
我们可以通过UWP Community Toolkit Notifications nuget 包轻松实现 toast 通知。如果您想为 引用 Web 图像 AppLogoOverride
,请创建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);
如何正确引用资源图标?
如果要引用资源图标和 Assets 文件夹中的图标资源,可以参考以下代码。
new AdaptiveImage()
{
Source = "Assets/Apps/Food/RestaurantMap.jpg"
}
Toast 通知图标中允许使用哪些图像类型?我可以参考,例如 .svg 图像吗?
对于我的测试png、jpg和svg图像可用于 toast 通知。
推荐阅读
- assembly - 对 6502 间接 x 和 y 的包装感到困惑
- java - 进程 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' 以非零退出值 1 结束
- sublimetext3 - 如果我有一个 JSON 对象数组,如何在 Sublime Text 3 中按“{”折叠?
- java - 无法在@Override 方法之外获取选定的微调器项目并进入另一个类
- c# - 使用 Azure SDK C# 创建和删除可用性测试
- python - 调用类变量时打印消息
- jquery - 通过 Safari 从 API 刷新数据的问题
- c++ - 无锁向量的实现
- sql-server - 如何求和不同的值数据透视表
- python - 时区时间戳怪异