Windows Phone 8提醒,具有自定义重复间隔

时间:2013-07-30 06:11:59

标签: c# windows-phone-8 windows-phone

有没有办法让Reminder处理自定义重复间隔,例如每4个小时?因为现在我知道的唯一选择是将RecurrenceType设置为RecurrenceInterval,这仅支持每日,每周,每月和每年的重复次数。

2 个答案:

答案 0 :(得分:2)

您可以通过这种方式在特定时间内每4小时重复提醒一次:

    private int _intervalHours;
    public int IntervalHours
    {
        get
        {
            return _intervalHours;
        }
        set
        {
            _intervalHours = value;
            RaisePropertyChanged("IntervalHours");
        }
    }

    private int _frequency;
    public int Frequency
    {
        get
        {
            return _frequency;
        }
        set
        {
            _frequency = value;
            RaisePropertyChanged("Frequency");
        }
    }
      //RecurrenceInterval.None is used as a new reminder will be created for every 4  hours in your case
      RecurrenceInterval recurrence = RecurrenceInterval.None;

      //inserting staring reminder
      name = System.Guid.NewGuid().ToString();
      reminder = new Reminder(name);
      reminder.RecurrenceType = recurrence;
      reminder.Title = title;
      reminder.Content = content;
      reminder.BeginTime = beginTime;
      reminder.ExpirationTime = expirationTime;
      reminder.RecurrenceType = recurrence;
      reminder.NavigationUri = navigationUri;
      ScheduledActionService.Add(reminder);

       //inserting reminder for IntervalHours, let say at interval of 4 hours and will added after each IntervalHours upto Frequency(number of time)
       if (IntervalHours > 0)
        {
            //i is started from 1 as 1 reminder added above
            for (int i = 1; i < Frequency; i++)
            {                    
                name = System.Guid.NewGuid().ToString();
                reminder = new Reminder(name);
                reminder.RecurrenceType = recurrence;
                reminder.Title = title;
                reminder.Content = content;
                reminder.BeginTime = beginTime.AddHours(IntervalHours*i);
                reminder.ExpirationTime = expirationTime.AddHours(IntervalHours*i);
                reminder.RecurrenceType = recurrence;
                reminder.NavigationUri = navigationUri;
                ScheduledActionService.Add(reminder);
            }
        }

希望这会有所帮助。

答案 1 :(得分:-1)

目前在WP8中它不支持。