【发布时间】:2015-08-12 10:12:08
【问题描述】:
我从 Windows 8.1 开始使用桌面应用程序的 toast 通知,但在 Windows 10 中使用新的操作中心时,我遇到了一些意外行为。
当用户对 toast 什么都不做时,它会直接消失而不去操作中心(ToastNotification.Dismissed 是 ToastDismissalReason.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