如何将联系人列表与手机号码集成到WP7应用程序中?

时间:2012-02-06 12:38:35

标签: c# .net windows-phone-7.1

我想在我的应用中显示联系人列表。这是一项简单的任务,请参阅this answered SO question。 但是,我只需要显示有手机号码的联系人。

如何实现这一目标?有没有办法使用LINQ?

〜克里斯

1 个答案:

答案 0 :(得分:2)

example from MSDN的基础上,您可以执行以下操作:

private void Button_Click(object sender, RoutedEventArgs e)
{
  Contacts cons = new Contacts();

  //Identify the method that runs after the asynchronous search completes.
  cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

  //Start the asynchronous search.
  cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
  var myMobilePhoneContacts = new List<Contact>();

  foreach (var contact in e.Results)
  {
    myMobilePhoneContacts.AddRange((from phoneNumber in contact.PhoneNumbers
                where phoneNumber.Kind == PhoneNumberKind.Mobile
            select contact).Select(cont => (Contact)cont));
  }

  // do something with the contacts in myMobilePhoneContacts
}