【问题标题】:Unexpected behaviours in toast notification from desktop app in Windows 10Windows 10 中桌面应用程序的 toast 通知中出现意外行为
【发布时间】:2015-08-12 10:12:08
【问题描述】:

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

当用户对 toast 什么都不做时,它会直接消失而不去操作中心(ToastNotification.DismissedToastDismissalReason.TimedOut)。我不知道这是否与我在 win32 应用程序中使用它有关,但 Windows 通用应用程序中的同一个 toast 在超时时会转到操作中心。

需要注意的一点是,我没有像 W8.1 中那样为我的 win32 应用程序注册 AppUserModelID,这似乎不再是强制性的。我仍然使用注册的 id 进行测试,并且遇到了同样的问题。

那么,如何防止 toast 在超时时不进入操作中心?

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

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

感谢您的帮助。

编辑:我在the msdn blog post 上发布了这个涵盖该主题的错误,并且我得到确认它应该在超时时保留在操作中心并且它可能是一个错误。

【问题讨论】:

    标签: c# notifications toast windows-10


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      COM 方法的替代方法是为您的应用使用set a registry key。在您的情况下将 irssi 替换为 ToastDesktop

      【讨论】:

        猜你喜欢
        • 2015-12-23
        • 2015-04-20
        • 1970-01-01
        • 2017-02-06
        • 2014-11-29
        • 1970-01-01
        • 1970-01-01
        • 2014-09-17
        • 2018-05-27
        相关资源
        最近更新 更多