ContactPickerUI 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
可讓您呼叫連絡人選擇器 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
- 繼承
- 屬性
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 |
指定使用者選取一或多個連絡人之後所要傳回的欄位。 注意 DesiredFields 可能會在Windows 8.1之後變更或無法使用。 請改用 DesiredFieldsWithContactFieldType。 |
DesiredFieldsWithContactFieldType |
取得在使用者選取一或多個連絡人之後,您想要傳回之連絡人欄位類型的欄位。 |
SelectionMode |
決定連絡人選擇器的選取模式。 最常見的選項是 PickSingleContactAsync 或 PickMultipleContactsAsync。 |
方法
AddContact(Contact) |
新增 連絡人。 |
AddContact(String, Contact) |
新增 連絡人。 注意 addContact 可能會在Windows 8.1之後變更或無法使用版本。 請改用不含識別碼的 AddContact 。 |
ContainsContact(String) |
檢查使用者是否已選取連絡人。 |
RemoveContact(String) |
移除連絡人。 |
事件
ContactRemoved |
發生于使用者取消選取或移除連絡人時。 |