In this article I will talk about SaveAppointmentTask class of Microsoft.Phone.Tasks. One can use SaveAppointmentTask in the application to launch calendar application with new appointment. It allows user to add an appointment to their calendar from application.
Let's write some code.
Step 1: Create a button in the MainPage.xaml to get appointment details.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button x:Name="btnSaveAppointmentTask" Content="Save Appointment " Click="btnSaveAppointmentTask_Click_1"></Button>
Step 2: Add Microsoft.Phone.Tasks.
Instance of SaveAppointmentTask allows user to set various properties as shown in below image.
SaveAppointmentTask create instance of SaveAppointmentTask
Show method shows the calendar application with a new appointment displayed.
AppointmentStatus gets or sets the appointment status on launch of Calendar application
Details gets or sets the details text of appointment on launch of calendar application
EndTime gets or sets the end time of appointment on launch of calendar application
IsAllDayEvent gets or sets whether new appointment shown is an all day event on lauch of calendar application
Location gets or sets the location string of appointment on launch of calendar application
Reminder gets or sets the reminder time of appointment on launch of calendar application
StartTime gets or sets the start time of appointment on launch of calendar application
Subject gets or sets the subject of appointment on launch of calendar application
Step 3: Add btnSaveAppointmentTask_Click_1 event in the codebehind of MainPage.xaml which will be invoked on click on button.
private void btnSaveAppointmentTask_Click_1(object sender, RoutedEventArgs e)
SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();
saveAppointmentTask.StartTime = DateTime.Now.AddHours(2);
saveAppointmentTask.EndTime = DateTime.Now.AddHours(3);
saveAppointmentTask.Subject = "Appointment subject";
saveAppointmentTask.Location = "Appointment location";
saveAppointmentTask.Details = "Appointment details";
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Reminder.FifteenMinutes;
saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.Busy;
Reminder has below Enum.
None = 0
AtStartTime = 1
FiveMinutes = 2
TenMinutes = 3
FifteenMinutes = 4
ThirtyMinutes = 5
OneHour = 6
EighteenHours = 7
OneDay = 8
OneWeek = 9
and Appointment has below Enum.
Free = 0
Tentative = 1
Busy = 2
OutOfOffice = 3
Step 4: Now run the application and you will get the screen like below.
Step 5: Save the appointment and go to start screen, you will get appointment on calendar tile as shown below.
Step 6: Let's put StartTime greater than EndTime and debug the code.
Debug the code and you will notice below error on execution of Show.
This ends the article of saving appointment using SaveAppointmentTask.