EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

ContactPickerUI class

Applies to Windows only

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

Syntax


public sealed class ContactPickerUI

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:


        ContactPickerUI contactPickerUI = MainPagePicker.Current.contactPickerUI;
        CoreDispatcher dispatcher = Window.Current.Dispatcher;

        public ContactPickerPage()
        {
            this.InitializeComponent();
            ContactList.ItemsSource = contactSet;
            ContactList.SelectionChanged += ContactList_SelectionChanged;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            contactPickerUI.ContactRemoved += contactPickerUI_ContactRemoved;
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            contactPickerUI.ContactRemoved -= contactPickerUI_ContactRemoved;
        }

        async void contactPickerUI_ContactRemoved(ContactPickerUI sender, ContactRemovedEventArgs args)
        {
            // The event handler may be invoked on a background thread, so use the Dispatcher to run the UI-related code on the UI thread.
            string removedId = args.Id;
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (SampleContact contact in ContactList.SelectedItems)
                {
                    if (contact.Id == removedId)
                    {
                        ContactList.SelectedItems.Remove(contact);
                        OutputText.Text += "\n" + contact.DisplayName + " was removed from the basket";
                        break;
                    }
                }
            });
        }


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


            switch (contactPickerUI.AddContact(contact))
            {
                case AddContactResult.Added:
                    // Notify the user that the contact was added
                    OutputText.Text = contact.DisplayName + " was added to the basket";
                    break;
                case AddContactResult.AlreadyAdded:
                    // Notify the user that the contact is already added
                    OutputText.Text = contact.DisplayName + " is already in the basket";
                    break;
                case AddContactResult.Unavailable:
                default:
                    // Notify the user that the basket is unavailable
                    OutputText.Text = 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.


            foreach (SampleContact removed in e.RemovedItems)
            {
                if (contactPickerUI.ContainsContact(removed.Id))
                {
                    contactPickerUI.RemoveContact(removed.Id);
                    OutputText.Text = removed.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

 

 

Mostrar:
© 2014 Microsoft. Todos os direitos reservados.