How to retrieve appointments in UWP from a Windows 10 calendar using C#

后端 未结 2 1185
清酒与你
清酒与你 2021-01-15 19:37

I\'m creating a Universal Windows Application in windows 10 using C# which manages appointments in the Windows Calendar App. I am able to add appointments, and can edit or d

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 20:32

    You can retrieve all the calendar appointments using the Windows.ApplicationModel.Appointments.AppointmentStore class.

    In this example I am going to retrieve the appointments in the next 24 hours

    AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
    
    var dateToShow = DateTime.Now.AddDays(0);
    var duration = TimeSpan.FromHours(24);
    
    var appCalendars = await appointmentStore.FindAppointmentsAsync(dateToShow, duration);
    foreach (var calendar in appCalendars)
    {
    [...]
    }
    

    Remember to grant access to Apointments Capabilities in the package.appxmanifest

提交回复
热议问题