ContactPickerUI 类

定义

允许你调用联系人选取器 UI,以便可以选择一个或多个联系人。

public ref class ContactPickerUI sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class ContactPickerUI final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class ContactPickerUI
Public NotInheritable Class ContactPickerUI
继承
Object Platform::Object IInspectable ContactPickerUI
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
应用功能
contactsSystem

示例

此示例代码准备页面以使用 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;
            }
        }
    });
}

此示例代码演示如何使用 AddContact (Contact) 方法将联系人添加到购物篮。

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;
}

此示例代码演示如何从购物篮中删除联系人并响应其删除。

foreach (SampleContact removed in e.RemovedItems)
{
    if (contactPickerUI.ContainsContact(removed.Id))
    {
        contactPickerUI.RemoveContact(removed.Id);
        OutputText.Text = removed.DisplayName + " was removed from the basket";
    }
}

注解

若要查看如何使用此类的示例,检查我们的代码示例

属性

DesiredFields

指定要在用户选择一个或多个联系人后返回的字段。

注意

在Windows 8.1后,DesiredFields 可能会更改或不可用于发布。 请改用 DesiredFieldsWithContactFieldType

DesiredFieldsWithContactFieldType

获取要在用户选择一个或多个联系人后返回的联系人字段类型的字段。

SelectionMode

确定联系人选取器的选择模式。 最常见的选项是 PickSingleContactAsyncPickMultipleContactsAsync

方法

AddContact(Contact)

添加 联系人

AddContact(String, Contact)

添加 联系人

注意

AddContact 可能会在Windows 8.1后更改或不适用于发布。 请改用不带 ID 的 AddContact

ContainsContact(String)

检查用户是否已选择联系人。

RemoveContact(String)

删除联系人。

事件

ContactRemoved

当用户取消选择或删除联系人时发生。

适用于