【问题标题】:How to remove a scheduled toast notification如何删除预定的 Toast 通知
【发布时间】:2013-03-06 20:09:28
【问题描述】:

我知道如何安排 Toast 通知 从这个样本 http://code.msdn.microsoft.com/windowsapps/Schedules-Toast-notificatio-457e599b#content

但现在我想做的是知道如何删除已创建的吐司 我试过这段代码,但它不工作

IReadOnlyList<ScheduledToastNotification> scheduled =
    ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();

foreach (ScheduledToastNotification notify in scheduled)
{
    if (notify.Id == id)
    {
        ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(notify);
    }
}

【问题讨论】:

  • 此代码有效。您是否在创建通知 ID 时设置它?您需要设置它并保留已创建通知的 ID 列表,以便以后可以取消它。

标签: c# xaml windows-8


【解决方案1】:

您可以使用 Clear 方法删除计划的磁贴通知。 详情见How to reset the TileUpdateManager from all scheduled tile notifications?

【讨论】:

  • 我不想清除所有的 toast .. 这里每个 toast 在调用函数 .GetScheduledToastNotifications() 后都有一个 ID 我在调试中知道它返回一个空的 toast .. 顺便说一句谢谢:)
  • 那么你看到了什么? Id 为空/null 或者 id 匹配但对 RemoveFromSchedule 的调用似乎不起作用(因为您可能会看到稍后出现的 toast)?
  • 是的,ID 是空的 .. 很抱歉,我现在意识到我的代码出了什么问题,这个函数是正确的,现在可以工作了 :).. 谢谢和抱歉
  • 那么您是要更新您的问题还是说明问题出在哪里?
【解决方案2】:

来自Microsoft example,问题在于您创建了多个 toast 通知程序。相反,您应该使用相同的 toast 通知程序来删除您的预定通知。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多