我尝试使用自定义音频创建Toast通知。程序运行时,程序可以显示吐司。我也在ListBox上添加了toast列表。它可以顺利显示通知,但无法从列表框中删除toast。
这是添加toast的代码:
public void Add(ref ListBox display, string value, string value2, TimeSpan occurs)
{
DateTime when = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
occurs.Hours, occurs.Minutes, occurs.Seconds);
if (when > DateTime.Now)
{
// Construct the toast content
ToastContent toastContent = new ToastContent()
{
//toast display here
};
//audio
// And create the toast notification
ScheduledToastNotification toast = new ScheduledToastNotification(toastContent.GetXml(), when);
// And then send the toast
toast.Id = random.Next(1, 100000000).ToString();
ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
display.Items.Add(new Item { Id = toast.Id, Content = value, Time = when.ToString() });
}
}
这是从列表框中删除吐司:
public void Remove(ListBox display)
{
if (display.SelectedIndex > -1)
{
ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
notifier.RemoveFromSchedule(notifier.GetScheduledToastNotifications().Where(
p => p.Id.Equals(((Item)display.SelectedItem).Id)).SingleOrDefault());
display.Items.RemoveAt(display.SelectedIndex);
}
}