Windows 10 中桌面应用程序的 toast 通知中出现意外行为 [英] Unexpected behaviours in toast notification from desktop app in Windows 10

查看:30
本文介绍了Windows 10 中桌面应用程序的 toast 通知中出现意外行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 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 对于我的 win32 应用程序,就像 W8.1 中需要的那样,它似乎不再是强制性的.我仍然使用注册的 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 服务器才能在 Action Center 中持久化 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 中桌面应用程序的 toast 通知中出现意外行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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