如何在Windows 8应用程序中安排特定日期和时间的Toast通知?

时间:2015-03-19 07:41:40

标签: c# xaml windows-8 windows-store-apps

对于日历应用,我希望为c#中的Windows应用安排特定日期和时间的吐司通知,例如18/3/2015 4:00 PM。我制作了3个组合框(NewEventYear)&等等。我正在尝试的是......

int x = int.Parse(NewEventYear.SelectedItem.ToString());

/* y & z for month and date respectively */

DateTime EventDate = new DateTime(x,y,z);

ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, EventDate);

我收到错误

  

" FormatException未被用户代码处理:输入字符串不在   格式正确"

指着

int x = int.Parse(NewEventYear.SelectedItem.ToString());

2 个答案:

答案 0 :(得分:2)

感谢您的帮助。通过编写此代码解决了我的问题。

int x = int.Parse(NewEventYear.SelectedItem.ToString());          
int y = int.Parse(NewEventMonth.SelectedItem.ToString());
int z = int.Parse(NewEventDate.SelectedItem.ToString());
int a = int.Parse(NewEventHour.SelectedItem.ToString());
int b = int.Parse(NewEventMinutes.SelectedItem.ToString()); 

DateTime EventDate = new DateTime(x,y,z,a,b,0)
TimeSpan NotTime = EventDate.Subtract(DateTime.Now);
DateTime dueTime = DateTime.Now.Add(NotTime);

ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);

答案 1 :(得分:1)

您可以使用的是

ObservableCollection<DateTime> myDateTimeCollection = new ObservableCollection<DateTime>();
myDateTimeCollection.Add(DateTime.Now); // add more members

myComboBox.ItemsSource = myDateTimeCollection;

DateTime selectedDateTime = (DateTime)myComboBox.SelectedItem; //add this in myComboBox_SelectionChanged event