WPF桌面应用程序,Windows 10 Notification Toast 2016(UWP社区工具包) [英] WPF Desktop App, Windows 10 Notification Toast 2016 (UWP Community Toolkit)

查看:534
本文介绍了WPF桌面应用程序,Windows 10 Notification Toast 2016(UWP社区工具包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我的 WPF C#桌面应用程序显示Windows 10 Toast.

I'm trying to display Windows 10 Toasts with my WPF C# Desktop application.

可悲的是,与非UWP或Store应用程序中的Windows 10通知有关的API和常规支持似乎非常有限且混乱. 最近发布了 UWP社区工具包,它似乎试图使我们更轻松. 还有这个商店应用, Notifications Visualizer ,它可以帮助您制作这样的敬酒:

Sadly the API and general support concerning Windows 10 notifications in non-UWP or Store apps seems pretty limited and chaotic. Lately the UWP Community Toolkit was published, which seems to try and make things easier for us. There's also this Store app, Notifications Visualizer, which helps in making Toasts like this:

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

I went on and tried to generated the Toast using C# and the API provided by the UWP Community Toolkit.

使用Microsoft.Toolkit.Uwp.Notifications;

using 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:

我发现的有关这些通知的大多数信息都是过时的或无用的. 有人可以说明一下吗? 谢谢.

Most information I found concerning these notifications are either outdated or useless. Can someone please shed some light on this? Thank you.

推荐答案

仅靠UWP Toolkit不能做到这一点

.NET Standard似乎只能分两步实现,而其中之一超出了UWP Toolkit的范围.

No way of doing this with the UWP Toolkit alone

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 Apps需要COM服务器和 special 开始"菜单快捷方式才能正确使用Windows 10操作中心. UWP Apps似乎不需要或已经具有等效功能. 这两个步骤应该在应用程序安装期间执行,而且显然,Microsoft UWP Toolkit不参与其中. 因此,仅UWP Toolkit不仅不能,而且永远无法提供以自成体系的方式显示.NET Standard的Windows 10 Toast的完整解决方案.

.NET Standard Apps require a COM Server and a special Start Menu Shortcut to properly use the Windows 10 Action Center. UWP Apps seem to not require or already come with an equivalent functionality. 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.

我在Github上发现了一个晦涩的 C#项目名称中带有"Microsoft"的名称,它可以在没有UWP Toolkit的情况下即开即用. 它要求您提供一个GUID和一个AppID字符串,然后将其用于注册COM服务器并创建快捷方式.

I found an obscure C# Project on Github that has 'Microsoft' in its name, it works out of the box without the UWP Toolkit. It requires you to provide a GUID and an AppID string which then is used to register the COM Server and create the Shortcut.

外观更简洁的替代方法是此库,它似乎提供了相同的功能.我仍然必须对其进行测试.

A cleaner looking alternative is this library which seems to provide the same functionality. I still have to test it.

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

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.

这篇关于WPF桌面应用程序,Windows 10 Notification Toast 2016(UWP社区工具包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆