Share via


Appointments.SearchCompleted Event

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Occurs when a search for appointments completes.

Namespace:  Microsoft.Phone.UserData
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
XMLNS for XAML: Not mapped to an xmlns.

Syntax

Public Event SearchCompleted As EventHandler(Of AppointmentsSearchEventArgs)
public event EventHandler<AppointmentsSearchEventArgs> SearchCompleted
<object SearchCompleted="EventHandler<AppointmentsSearchEventArgs>" .../>

Remarks

To associate this event with a method that will handle the event, create a delegate and add an instance of the delegate to the event. The event handler is called whenever this event occurs, unless you remove the delegate.

For more information about handling events, see Consuming Events.

Examples

The following example assumes that you have a Windows Phone application that has a page with a button named SearchAppointments. The code assumes that you have a databound list box named AppointmentResultsData. In this example, you search for all appointments in the next seven days. For the full example, including the XAML, see How to access calendar data for Windows Phone 8.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;

namespace ContactsAndCalendarTestApp
{
    public partial class AppointmentsPage : PhoneApplicationPage
    {
        public AppointmentsPage()
        {
            InitializeComponent();
        }


        private void SearchAppointments_Click(object sender, RoutedEventArgs e)
        {
            AppointmentResultsData.DataContext = null;
            Appointments appts = new Appointments();

            appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);

            DateTime start = new DateTime();
            start = DateTime.Now;
            //MessageBox.Show(start.ToLongDateString());

            DateTime end = new DateTime();
            end = start.AddDays(7);
            //MessageBox.Show(end.ToLongDateString());

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


        void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            //MessageBox.Show(e.State.ToString());
            //MessageBox.Show(e.StartTimeInclusive.ToShortDateString());
            //MessageBox.Show(e.EndTimeInclusive.ToShortDateString());
        
            try
            {
                //Bind the results to the list box that displays them in the UI.
                AppointmentResultsData.DataContext = e.Results;
            }
            catch (System.Exception)
            {
                //That's okay, no results.
            }
        }
    }
}
Imports Microsoft.Phone.UserData

Partial Public Class AppointmentsPage
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()
    End Sub


    Private Sub SearchAppointments_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)

        AppointmentResultsData.DataContext = Nothing
    
        Dim appts As Appointments = new Appointments()

        AddHandler appts.SearchCompleted, AddressOf Appointments_SearchCompleted

        Dim start As DateTime = DateTime.Now
        Dim endTime As DateTime = start.AddDays(7)

        appts.SearchAsync(start, endTime, 20, "Appointments Test #1")
    End Sub


    Private Sub Appointments_SearchCompleted(sender As Object, e As AppointmentsSearchEventArgs)

        'MessageBox.Show(e.State.ToString())
        'MessageBox.Show(e.StartTimeInclusive.ToShortDateString())
        'MessageBox.Show(e.EndTimeInclusive.ToShortDateString())

        Try
            'Bind the results to the list box that displays them in the UI.
            AppointmentResultsData.DataContext = e.Results

        Catch ex As System.Exception

            'That's okay, no results.
        End Try
    End Sub
End Class

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Platforms

Windows Phone

See Also

Reference

Appointments Class

Microsoft.Phone.UserData Namespace

Other Resources

Contacts and Calendar for Windows Phone 8

How to access calendar data for Windows Phone 8