Contacts.SearchCompleted Event

July 28, 2014

Occurs when a search for contacts completes.

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

public event EventHandler<ContactsSearchEventArgs> SearchCompleted
<object SearchCompleted="EventHandler<ContactsSearchEventArgs>" .../>

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.

The following example assumes that you have a Windows Phone application that has a page with a button named SearchContacts. The code assumes that you have a databound list box named ContactResultsData. For the full example, including the XAML, see How to access contact 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 ContactsPage : PhoneApplicationPage
    {
        // Constructor
        public ContactsPage()
        {
            InitializeComponent();
        }


        private void SearchContacts_Click(object sender, RoutedEventArgs e)
        {
            ContactResultsData.DataContext = null;

            Contacts cons = new Contacts();

            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

            cons.SearchAsync(“A”, FilterKind.DisplayName, "Contacts Test #1");
        }


        void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            //MessageBox.Show(e.State.ToString());

            try
            {
                //Bind the results to the list box that displays them in the UI.
                ContactResultsData.DataContext = e.Results;
            }
            catch (System.Exception)
            {
                //That's okay, no results.
            }
        }
    }
}

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2014 Microsoft