我从 Windows 8.1 开始使用桌面应用程序的 toast 通知,但在 Windows 10 中使用新的操作中心时,我遇到了一些意外行为。
当用户对 toast 不做任何操作时,它会直接消失而无需转到操作中心(ToastNotification.Dismissed
为 ToastDismissalReason.TimedOut
)。我不知道这是否与我在 win32 应用程序中使用它有关,但 Windows 通用应用程序中的相同 toast 在超时时会转到操作中心。
需要注意的是,我还没有注册 AppUserModelID对于我的 win32 应用程序,就像 W8.1 中需要的那样,它似乎不再是强制性的了。我仍然使用已注册的 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 上发布了这个错误涵盖了主题,我得到确认它应该在超时时保留在操作中心并且它可能是一个错误。
最佳答案
Win32 应用程序需要设置一个 COM 服务器,以便在 Action Center 中保留 toasts:http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/10/15/quickstart-handling-toast-activations-from-win32-apps-in-windows-10.aspx
关于c# - 来自 Windows 10 桌面应用程序的 Toast 通知中的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31962216/