简体   繁体   English

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

[英]WPF Desktop App, Windows 10 Notification Toast 2016 (UWP Community Toolkit)

I'm trying to display Windows 10 Toasts with my WPF C# Desktop application . 我正在尝试使用我的WPF C#Desktop应用程序显示Windows 10 Toast。

Sadly the API and general support concerning Windows 10 notifications in non-UWP or Store apps seems pretty limited and chaotic. 可悲的是,关于非UWP或商店应用程序中的Windows 10通知的API和一般支持似乎非常有限和混乱。 Lately the UWP Community Toolkit was published, which seems to try and make things easier for us. 最近发布了UWP社区工具包 ,它似乎试图让我们更容易。 There's also this Store app, Notifications Visualizer , which helps in making Toasts like this: 还有这个商店应用程序Notifications Visualizer ,它可以帮助制作像这样的Toasts:

在此输入图像描述

I went on and tried to generated the Toast using C# and the API provided by the UWP Community Toolkit. 我继续尝试使用C#和UWP社区工具包提供的API生成Toast。

using Microsoft.Toolkit.Uwp.Notifications; 使用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

Unfortunately, no matter what I try, I seem to be unable to get the same result, the Image is always missing for some reason: 不幸的是,无论我尝试什么,我似乎都无法得到相同的结果,因为某些原因,Image总是丢失:

在此输入图像描述

Most information I found concerning these notifications are either outdated or useless. 我发现的有关这些通知的大多数信息都已过时或无用。 Can someone please shed some light on this? 有人可以对此有所了解吗? Thank you. 谢谢。

No way of doing this with the UWP Toolkit alone 单凭UWP Toolkit无法做到这一点

It looks like with .NET Standard this can only be achieved in two steps, and one of them is out of the scope of the UWP Toolkit. 看起来使用.NET Standard,这只能通过两个步骤实现,其中一个不在UWP Toolkit的范围内。

.NET Standard Apps require a COM Server and a special Start Menu Shortcut to properly use the Windows 10 Action Center. .NET标准应用程序需要COM服务器和特殊的“开始”菜单快捷方式才能正确使用Windows 10操作中心。 UWP Apps seem to not require or already come with an equivalent functionality. UWP Apps似乎不需要或已经具有同等功能。 These two steps are supposed to be performed during application installation , and this is obviously something the Microsoft UWP Toolkit takes no part in. Thus the UWP Toolkit alone is not only unable but never will be able to provide a complete solution for displaying Windows 10 Toasts for .NET Standard in a self contained way. 这两个步骤应该在应用程序安装期间执行 ,这显然是微软UWP工具包不参与的事情。因此,单独的UWP工具包不仅无法,而且永远无法提供显示Windows 10 Toast的完整解决方案。对于.NET Standard的自包含方式。

Alternatives 备择方案

I found an obscure C# Project on Github that has 'Microsoft' in its name, it works out of the box without the UWP Toolkit. 在Github上发现了一个名不见经传的C#项目 ,其名称中包含“Microsoft”,它在没有UWP工具包的情况下开箱即用。 It requires you to provide a GUID and an AppID string which then is used to register the COM Server and create the Shortcut. 它要求您提供GUID和AppID字符串,然后用于注册COM服务器并创建快捷方式。

A cleaner looking alternative is this library which seems to provide the same functionality. 一个看起来更干净的替代品是这个库似乎提供相同的功能。 I still have to test it. 我还是要测试一下。

Both these solutions should work with Microsoft's NotificationsExtensions librabry, which is a precursor of the UWP Toolkit and helps with generating the XML code Toasts are made of. 这两个解决方案都应该与Microsoft的NotificationsExtensions librabry一起使用,它是UWP Toolkit的前身,有助于生成由Toast组成的XML代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM