如何使用silverlight和c#以编程方式阅读Windows Phone 7中的联系人?

时间:2011-05-24 09:27:30

标签: silverlight windows-phone-7

如何使用silverlight和c#以编程方式阅读Windows Phone 7中的联系人?

2 个答案:

答案 0 :(得分:2)

现在,您只能通过EmailAddressChooserTask API一次访问一个联系人。没有办法阅读整个联系人列表。

答案 1 :(得分:0)

如果您使用的是Windows Phone 7.0,则一次只能阅读一个联系人。如此使用EmailAddressChooserTaskPhoneNumberChooserTask,您可以使用EmailAddressChooserTask执行相同操作:

private PhoneNumberChooseTask myPhoneChooserTask;

public MainPage()
{
   InitializeComponent();
   myPhoneChooserTask = new PhoneNumberChooseTask ();
   myPhoneChooserTask.Completed += (o, e) => 
   {
      if (e.TaskResult == TaskResult.OK)
         //Here means the phone is chosen successfully. you can access the phone number with e.PhoneNumber
      else
         //Here means the phone is not chosen
   }
   myPhoneChooserTask.Show(); //Show contact list for choosing
}

但是,使用Windows OS 7.1,您可以使用联系人搜索读取所有联系人,如下所示使用空字符串。取自http://msdn.microsoft.com/en-us/library/hh286416(v=vs.92).aspx

private void ButtonContacts_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)
{
    //Do something with the results.
    MessageBox.Show(e.Results.Count().ToString());
}
祝你好运!