编辑:新问题 - 为了清楚起见和新代码,请参阅在 windows phone 8 中选择联系人
谁投了反对票,非常感谢。很有建设性。
感谢 MSDN 和这里的支持,我得到了以下代码,它填充了一个联系人列表,并允许用户在将它们保存到 List 对象之前选择多个联系人。
但是,我现在想知道如何检索与检索到的每个名称相关联的联系号码。我已经尝试过随后的搜索,但我觉得我做错了,每次它都破坏了代码。
任何帮助将不胜感激,谢谢。
private void showContacts(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());
try
{
//Bind the results to the user interface.
ContactResultsData.DataContext = e.Results;
}
catch (System.Exception)
{
//No results
}
if (ContactResultsData.Items.Any())
{
ContactResultsLabel.Text = "results";
}
else
{
ContactResultsLabel.Text = "no results";
}
}
public void saveContacts(object sender, RoutedEventArgs e)
{
String strItem;
List<string> listOfNames = new List<string>();
foreach (Object selecteditem in ContactResultsData.SelectedItems)
{
//MessageBox.Show(selecteditem.ToString());
strItem = selecteditem as String;
ContactResultsLabel.Text = strItem;
listOfNames.Add(strItem);
//System.Diagnostics.Debug.WriteLine(strItem);
//MessageBox.Show("Saving " + strItem);
}
}
}
}