Windows 10 Toast通知图标引用

时间:2019-05-24 06:55:40

标签: c# wpf uwp windows-10 toast

我决定丢弃“旧学校”的Windows气球通知,并使用新的 Windows 10本机吐司通知。

现在,我正在努力为吐司通知引用一个图标。根据Microsocft文档(herehere),我应该能够像这样添加通知图标:

// 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);

相反,将显示一个默认的应用程序图标:

enter image description here

唯一有效的方法是使用图像的绝对路径:

"file:///" + Path.GetFullPath("../../Assets/myicon.png");

但是,这不能满足我的需求,因为我需要引用资源图标或Web上的图标。

提出我的问题:

  1. 如何在敬酒通知中正确引用网络图像(https://picsum.photos/48?image=883)?
  2. 如何正确引用资源图标?
  3. 土司通知图标中允许使用哪些图像类型?我可以引用例如.svg图片吗?

1 个答案:

答案 0 :(得分:0)

  

如何在敬酒通知中正确引用网络图像(https://picsum.photos/48?image=883)?

我们可以通过UWP Community Toolkit Notifications nuget package轻松实现敬酒通知。如果要引用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"
}
  

土司通知图标中允许使用哪种图像类型?我可以引用例如.svg图片吗?

对于我的测试 png jpg svg 图片可用于吐司通知。

相关问题