来自 Windows 10 桌面应用程序的吐司通知中的意外

时间:2022-12-03
本文介绍了来自 Windows 10 桌面应用程序的吐司通知中的意外行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Windows 8.1 开始使用桌面应用程序的 toast 通知,但使用 Windows 10 中的新操作中心,我遇到了一些意外行为.

I used the toast notifications for desktop app since Windows 8.1 but with the new action center in Windows 10, I am experiencing some unexpected behaviours.

当用户对 Toast 不做任何操作时,它会直接消失而无需进入操作中心(ToastNotification.DismissedToastDismissalReason.TimedOut).我不知道这是否与我在 win32 应用程序中使用它有关,但 Windows 通用应用程序中的相同 toast 在超时时进入操作中心.

When the user do nothing with the toast, it simply disappear without going to the action center (ToastNotification.Dismissed is ToastDismissalReason.TimedOut). I don't know if it related to the fact that I use it in a win32 app but the same toast in a Windows Universal App goes to the action center when it timed out.

需要注意的一点是我没有注册 AppUserModelID 对于我在 W8.1 中需要的 win32 应用程序,它似乎不再是强制性的.我仍然用注册的 id 测试,我也有同样的问题.

One thing to note is that I have not registered an AppUserModelID for my win32 app like it was needed in W8.1, it seems to not be mandatory anymore. I still tested with a registered id, and I had the same popblem.

那么,我怎样才能防止 toast 在超时时不进入操作中心?

So, how can i prevent the toast from not going in the action center when it timed out ?

这是重现问题的极简代码(控制台应用程序):

Here is a minimalist code (console app) that reproduces the issue :

using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;

namespace ToastDesktop
{
    internal class Program
    {
        /// Add in the .csproj in the <PropertyGroup/> where <TargetFrameworkVersion/> is:
        /// <TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
        ///
        /// Reference to add :
        /// - Windows.UI
        /// - Windows.Data
        private static void Main(string[] args)
        {
            string xml = $@"
                <toast>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>Some title</text>
                            <text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text>
                        </binding>
                    </visual>
                </toast>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            ToastNotification toast = new ToastNotification(doc);
            toast.Tag = "tag";
            toast.Group = "group";

            ToastNotificationManager.CreateToastNotifier("ToastDesktop").Show(toast);
        }
    }
}

感谢您的帮助.

我在 涵盖该主题的 msdn 博客文章,我得到确认,它应该在超时时保留在操作中心,并且它可能是一个错误.

Edit : I posted this bug on the msdn blog post that cover the subject and I got the confirmation that it should remain in the action center when timed out and that it might be a bug.

推荐答案

Win32 应用程序需要设置 COM 服务器才能在操作中心持久化 toast:http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/10/15/quickstart-handling-toast-activations-from-win32-apps-in-windows-10.aspx

Win32 apps need to set up a COM server in order to have toasts persisted in Action Center: http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/10/15/quickstart-handling-toast-activations-from-win32-apps-in-windows-10.aspx

这篇关于来自 Windows 10 桌面应用程序的吐司通知中的意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:显示 Windows 10 Toast 通知 下一篇:在 RegistryKey 值更改时收到通知

相关文章

最新文章