WPF桌面应用程序,Windows 10通知Toast 2016(UWP社区工具包)

r41*_*41n 7 c# wpf windows-10 windows-10-desktop windows-community-toolkit

我正在尝试使用我的WPF C#Desktop应用程序显示Windows 10 Toast .

可悲的是,关于非UWP或商店应用程序中的Windows 10通知的API和一般支持似乎非常有限和混乱.最近发布了UWP社区工具包,它似乎试图让我们更容易.还有这个商店应用程序Notifications Visualizer,它可以帮助制作像这样的Toasts:

在此输入图像描述

我继续尝试使用C#和UWP社区工具包提供的API生成Toast.

使用Microsoft.Toolkit.Uwp.Notifications;

ToastContent 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
            }
        }
    }
};


XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(toastContent.GetContent());

var toast = new ToastNotification(xmlDoc);
ToastNotificationManager.CreateToastNotifier(AppId).Show(toast); // Display toast
Run Code Online (Sandbox Code Playgroud)

不幸的是,无论我尝试什么,我似乎都无法得到相同的结果,因为某些原因,Image总是丢失:

在此输入图像描述

我发现的有关这些通知的大多数信息都已过时或无用.有人可以对此有所了解吗?谢谢.

r41*_*41n 9

单凭UWP Toolkit无法做到这一点

看起来使用.NET Standard,这只能通过两个步骤实现,其中一个不在UWP Toolkit的范围内.

.NET标准应用程序需要COM服务器和特殊的"开始"菜单快捷方式才能正确使用Windows 10操作中心.UWP Apps似乎不需要或已经具有同等功能.这两个步骤应该在应用程序安装期间执行,这显然是微软UWP工具包不参与的事情.因此,单独的UWP工具包不仅无法,而且永远无法提供显示Windows 10 Toast的完整解决方案.对于.NET Standard的自包含方式.

备择方案

我发现了一个不起眼的Github上C#项目具有"微软在它的名字,它的作品了没有UWP工具包框的.它要求您提供GUID和AppID字符串,然后用于注册COM服务器并创建快捷方式.

一个看起来更干净的替代品是这个库似乎提供相同的功能.我还是要测试一下.

这两个解决方案都应该与Microsoft的NotificationsExtensions librabry一起使用,它是UWP Toolkit的前身,有助于生成由Toast组成的XML代码.