Windows Phone 7 Reminders

半城伤御伤魂 提交于 2019-12-11 04:54:17

问题


Is there any way to set a reminder by Day of the week? For example if I want a reminder every Friday at 10am.

What is the best way to accomplish this task?

I think I've been over thinking some sort of hours calculation. I'm hoping there is a more simplistic way of doing what I'm looking to do.

Update:

My question is more about how to figure out how to set the reminder for a specific day even if it isn't today. So lets say today is Wednesday and I want to set a reminder for every Friday (or ANY day of the week)... How would I accomplish that?


回答1:


Since the reminder needs a DateTime its pretty easy. Each application has a max of 50 reminders:

DateTime dateTime = DateTime.Now; //First Friday at 10am
for (int i = 0; i < 50; i++)
{
    Reminder reminder = new Reminder("MyReminder")
    reminder.Content = "Reminder";
    reminder.BeginTime = dateTime.AddDays(i * 7);

    ScheduledActionService.Add(reminder);
}

-or this may work-

Reminder reminder = new Reminder("MyReminder")
reminder.Content = "Reminder";
reminder.BeginTime = DateTime.Now; //First Friday at 10am
reminder.Content = "Reminder";
reminder.ExpirationTime = DateTime.Now.AddDays(52 * 7);
reminder.RecurrenceType = RecurrenceInterval.Weekly; 

ScheduledActionService.Add(reminder);

EDIT

This is how you get the next day of week

private DateTime GetNextDay(string dayOfWeek)
{
    for (int i = 0; i < 7; i++)
    {
        DateTime currentDateTime = DateTime.Now.AddDays(i);
        if (dayOfWeek.Equals(currentDateTime.ToString("dddd")))
            return currentDateTime;
    }

    return DateTime.Now;
}


来源:https://stackoverflow.com/questions/9305937/windows-phone-7-reminders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!