1

我已经使用此代码成功添加了单个约会现在我想在单个循环中以编程方式添加多个约会。例如,我想使用循环一次添加 5 个约会,其中每个约会的日期都在列表中可用。提前致谢 :)

SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();          
saveAppointmentTask.StartTime = nearestDate;

saveAppointmentTask.EndTime = nearestDate.AddMinutes(3) ;

saveAppointmentTask.Subject = "Meet Ali"; // appointment subject

saveAppointmentTask.Location = "In Office"; // appointment location

saveAppointmentTask.Details = "Meet Ali to discuss product launch";//appointment details
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Microsoft.Phone.Tasks.Reminder.FifteenMinutes;
saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.OutOfOffice;
saveAppointmentTask.Show();
4

2 回答 2

1

您不能自动保存所有约会。您必须在每次迭代中启动任务,并且每次迭代都需要用户交互。

一个可能的选择是使用Live Connect API. 这将允许您以编程方式在用户的实时日历中创建 apointments:

与日历交互(Live Connect API)

这样你就不会与手机日历交互,而是与用户的 Live 日历交互,它可以在手机中同步。当然,用户需要进行身份验证。

于 2013-09-13T06:54:17.900 回答
1

使用此代码作为导航到事件在您登陆页面时始终调用

private SaveAppointmentTask saveAppointmentTask;
    private List<int> listMinutes = new List<int>();
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        for (int i = 0; i < 10; i++) {
            listMinutes.Add(i);
        }

    }

    int countAdded = 0;
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

        if (countAdded < 10)
        {

            saveAppointmentTask = new SaveAppointmentTask();
            saveAppointmentTask.StartTime = DateTime.Now.AddMinutes(listMinutes[countAdded]);

            saveAppointmentTask.EndTime = saveAppointmentTask.StartTime.Value.AddMinutes(2);

            saveAppointmentTask.Subject = "Meet Ali"; // appointment subject

            saveAppointmentTask.Location = "In Office"; // appointment location

            saveAppointmentTask.Details = "Meet Ali to discuss product launch";//appointment details
            saveAppointmentTask.IsAllDayEvent = false;
            saveAppointmentTask.Reminder = Microsoft.Phone.Tasks.Reminder.FifteenMinutes;
            saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.OutOfOffice;
            countAdded++;
            saveAppointmentTask.Show();
        }
        else { 
            // do not add anything
        }


    }

保存 i 这是某些应用程序状态或令牌中的计数,以便您可以知道是否添加了事件 :)Appplication.Current.Resources.Add("token", "number added")

谢谢

于 2013-09-13T07:19:12.183 回答