从 ActionCenter 移除 ToastNotification
Remove ToastNotification from ActionCenter
我在 Windows 10 中有一个桌面应用程序 运行,它创建的 ToastNotifications 也存储在 Action Center 中。我注意到,当我重新启动计算机时,操作中心中仍然存在通知,因此我想在不再需要它们时通过我的应用程序将其删除。
我想为此使用 ToastNotificationHistory Remove
方法。
我的代码如下所示:
public static void RemoveNotificationByTag(string toastTag)
{
ToastNotificationManager.History.Remove(toastTag, "TEST");
}
但这会导致这个异常:System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'
我之前发送的通知有一个 Tag
和一个 Group
值。
我在调用 RemoveGroup
或 GetHistory
方法时遇到相同的异常。基本上似乎我不能从历史 class 中调用任何方法而不得到相同的异常
在 Windows10 上,有必要为每个方法提供 applicationId 参数。此外,您不仅必须指定 toast 标签,还必须指定其组。
像这样调用方法有效:
ToastNotificationManager.History.Remove(toastTag, "TEST", appId);
我在 Windows 10 中有一个桌面应用程序 运行,它创建的 ToastNotifications 也存储在 Action Center 中。我注意到,当我重新启动计算机时,操作中心中仍然存在通知,因此我想在不再需要它们时通过我的应用程序将其删除。
我想为此使用 ToastNotificationHistory Remove
方法。
我的代码如下所示:
public static void RemoveNotificationByTag(string toastTag)
{
ToastNotificationManager.History.Remove(toastTag, "TEST");
}
但这会导致这个异常:System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'
我之前发送的通知有一个 Tag
和一个 Group
值。
我在调用 RemoveGroup
或 GetHistory
方法时遇到相同的异常。基本上似乎我不能从历史 class 中调用任何方法而不得到相同的异常
在 Windows10 上,有必要为每个方法提供 applicationId 参数。此外,您不仅必须指定 toast 标签,还必须指定其组。
像这样调用方法有效:
ToastNotificationManager.History.Remove(toastTag, "TEST", appId);