Introduction:
In this article we are going to see how to use the Calendar application to access the calendar data and use it across the development as and when needed. In our earlier article we have seen how to use the contacts and access the contact data, we are going to use the same process of accessing the calendar objects.
In order to use the calendar object we are going to use the reference of the Appointments object and do an Async search to get the results and show it on to a collection of Appointment objects. The end result in the appointments object can be used in different ways as per the requirement by binding to different controls and to do some schedule. Appointment class is to interact with user appointment data and is inherited from the Microsoft.Phone.UserData namespace. Let us see the step by step process on how to use the calendar objects and list the appointments. [more]
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application with a valid project name as shown in the screen below.
Now in order to fetch the details of the calendar appointments and show it to the end users, we will add controls from the tools as shown in the screen below. We can just drag and drop the controls from the tool box or write the XAML code as shown in the screen below or copy paste the XAML code.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we need to add code to do listing of the calendar appointments to the list view. First add the namespace
|
|
Now add the button click event code, here we are going to create an object of the Appointment class and do an AsyncSearch. We need to provide the start time and end time to fetch the appointment details and also should provide the maximum count. Copy and paste the below code to the code behind for the button click event.
C# Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now the above code will pull the information from the appointments object and bind it to the data context of the list box. If there is no appointments available we can see an empty result as well. To check the application just run the application by pressing F5 directly from the keyboard or by selecting build and execute solution from the tool bar and we can see the screen as shown in the screen below.
Since we are in the emulator and we don’t have any appointments saved the list is empty. If any appointments are saved in the physical device we will get the complete list of the next 10 days to be displayed here in the list box.
Conclusion:
So in this article we have seen how to use the calendar object to fetch the appointment details and list it out. We can customize to use the appointments object to bind to different data binding options as per the requirements.
No Comments
Rattling nice layout and wonderful content , practically nothing else we need : D.