I tried to create a toast notification with the custom audio. While the program running, the program can display the toast. I added list of toast on ListBox too. It works smoothly for displaying notification, but it cannot remove the toast from list box.
This is the code for adding 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() });
}
}
This is for removing toast from listbox:
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);
}
}