How to read appointments or calendar in Windows phone

How to read appointments or calendar in Windows phone

This article describes how to read appointments or calendar  data programmatically.

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

Accessing calendar data

To accessing calendar data is to get a reference to the Appointments object. It do an asynchronous search on it, and then capture the results as a collection of Appointment objects.

Include the ID_CAP_APPOINTMENTS capability in app manifest file.

 Create a new Windows Phone App and then select Windows Phone 8.0 as platform you want to target

Go to Solution Explorer , expand the Properties folder, and then double-click WMAppManifest.xml

Click on the Capabilities tab of the manifest designer, select the check box next to ID_CAP_APPOINTMENTS

Note: Windows Phone Emulator does not contain sample appointments. You should test these procedures using a physical device.












    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation ="Portrait"


    <!--Listbox Template-->


        <DataTemplate x:Key="AptItemTemplate">

            <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,10">


                    <ColumnDefinition Width="95"/>

                    <ColumnDefinition Width="*"/>


                <Border  Width="85" Height="85" Margin="5">

                    <TextBlock Text="{Binding StartTime}" Foreground="White" MaxHeight="60" TextWrapping="Wrap" FontWeight ="Bold"/>



                <StackPanel Grid.Column="1" Margin="10,0,0,0">

                    <TextBlock Text="{Binding Subject}" Foreground="White" MaxHeight="60" TextWrapping ="Wrap" FontWeight="Bold"/>

                    <TextBlock Text="{Binding Location}" Foreground="White" TextWrapping ="Wrap" />





    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">


            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>



         <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle }" Margin="12,0"/>

            <TextBlock Text="Appointments" Margin ="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style }"/>



        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <ListBox Name="AppointmentResultsData" Grid.Row="1" ItemsSource="{Binding}" ItemTemplate="{StaticResource AptItemTemplate }"  >







Add using statement in the top of the class

using Microsoft.Phone.UserData; 

Instantiate the Appointment object in the constructor of the class

public MainPage()


Appointments appts = new Appointments();

  //Identify the method that runs after the asynchronous search completes.

appts.SearchCompleted += appts_SearchCompleted;

DateTime start = DateTime.Now;

DateTime end = start.AddDays(7); //get the appointment for next 7 days 

//get Maximun 20 Appointments.

int max = 20;

appts.SearchAsync(start, end, max, "Appointments Test #1");



    void appts_SearchCompleted(object sender, AppointmentsSearchEventArgs e)




                AppointmentResultsData.DataContext =

                    from Appointment appt in e.Results

                    where appt.IsAllDayEvent == false

                    select appt;

                IEnumerable<Appointment> appointment = from Appointment appt in e.Results

                                                        where appt.IsAllDayEvent == false

                                                        select appt;


            catch (System.Exception)


                //No results



comments powered by Disqus

Related Articles