ContactPickerUI class

Applies to Windows only

Allows you to call the contact picker UI so you can select one or more contacts.

Syntax


/* For information about creating or accessing this object, see Remarks. */

Attributes

[Version(0x06020000)]

Members

The ContactPickerUI class has these types of members:

Events

The ContactPickerUI class has these events.

EventDescription
ContactRemoved Occurs when the user deselects or removes the contact.

 

Methods

The ContactPickerUI class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
AddContact(Contact) Adds a Contact. The Contact.Id property must be set when you call AddContact. If Contact.Id isn't set, your app will fail.
AddContact(String,Contact) AddContact may be altered or unavailable for releases after Windows 8.1. Instead, use AddContact without the ID. Adds a Contact.
ContainsContact Checks to see whether the contact was already selected by the user.
RemoveContact Removes a contact.

 

Properties

The ContactPickerUI class has these properties.

PropertyAccess typeDescription

DesiredFields

Read-onlyDesiredFields may be altered or unavailable for releases after Windows 8.1. Instead, use DesiredFieldsWithContactFieldType. Specifies the fields that you want returned after the user selects one or more contacts.

DesiredFieldsWithContactFieldType

Read-onlyGets the fields with contact field type that you want returned after the user selects one or more contacts.

SelectionMode

Read-onlyDetermines the selection mode for the contact picker. The most common options are PickSingleContactAsync or PickMultipleContactsAsync.

 

Remarks

To see an example of how to use this class, check out our code sample.

Examples

This example code prepares the page to use ContactPickerUI:



var contactPickerUI;

    var page = WinJS.UI.Pages.define("/html/contactPickerScenario.html", {
        processed: function (element, uri) {
            // During an initial activation this event is called before the system splash screen is torn down.
            sampleContacts.forEach(createContactUI);
        },

        ready: function (element, options) {
            // During an initial activation this event is called after the system splash screen is torn down.
            // Do any initialization work that is not related to getting the initial UI setup.
            contactPickerUI = options.contactPickerUI;
            contactPickerUI.addEventListener("contactremoved", onContactRemoved, false);
        },

        unload: function () {
            contactPickerUI.removeEventListener("contactremoved", onContactRemoved, false);
        }
});


This example code shows how to add a contact to the basket with the AddContact(Contact) method.



// Add the contact to the basket
var statusMessage = document.getElementById("statusMessage");
     switch (contactPickerUI.addContact(contact)) {
     case Windows.ApplicationModel.Contacts.Provider.AddContactResult.added:
         // Notify user that the contact was added to the basket
         statusMessage.innerText = contact.displayName + " was added to the basket";
         break;
     case Windows.ApplicationModel.Contacts.Provider.AddContactResult.alreadyAdded:
         // Notify the user that the contact is already in the basket
         statusMessage.innerText = contact.displayName + " is already in the basket";
         break;
     case Windows.ApplicationModel.Contacts.Provider.AddContactResult.unavailable:
     default:
         // Notify the user that the basket is not currently available
         statusMessage.innerText = contact.displayName + " could not be added to the basket";
         break;
}


This example code shows how to remove a contact from the basket and respond to its removal.


function removeContactFromBasket(sampleContact) {
    // Programmatically remove the contact from the basket
    if (contactPickerUI.containsContact(sampleContact.id)) {
        contactPickerUI.removeContact(sampleContact.id);
        document.getElementById("statusMessage").innerText = sampleContact.displayName + " was removed from the basket";
    }
}


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.Contacts.Provider
Windows::ApplicationModel::Contacts::Provider [C++]

Metadata

Windows.winmd

 

 

Show:
© 2014 Microsoft