将激活的事件添加到toast通知时出错

本文关键字:toast 通知 出错 添加 激活 事件 | 更新日期: 2023-09-27 18:27:47

我在程序中添加了一个toast通知,对它进行了编译,它按预期工作。

将显示toast通知。

之后,我添加了激活的事件:

toast.Activated += toast_Activated;
void toast_Activated(ToastNotification sender, object args)
{
}

当试图编译此代码时,我得到以下错误:

属性、索引器或事件"Windows.UI.Notifications.ToastNotification.Activated"不是语言支持;尝试直接调用访问器方法'Windows.UI.Notifications.ToastNotification.add_Activated(Windows.Foundation.TypedEventHandler)'或'Windows.UI.Notifications.ToastNotification.remove_Activated(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken)'

我做错了什么?

将激活的事件添加到toast通知时出错

当我从桌面应用程序示例中复制Sending toast通知时,我遇到了完全相同的问题。几个小时后,我检查了与示例的所有差异,发现我错误地添加了对"System.Runtime.InteropServices.dll"的引用,而不是"System.Runime.InteropServices.WindowsRuntime.dll"。将引用更改为后者,效果很好。