我根据我在 MSDN 中阅读的链接使用以下代码。
public async void getFavouriteList()
{
try
{
ContactStore store = await ContactStore.CreateOrOpenAsync();
var queryOptions = new ContactQueryOptions();
queryOptions.DesiredFields.Add(KnownContactProperties.DisplayName);
ContactQueryResult result = store.CreateContactQuery(queryOptions);
var contactCount = await result.GetContactCountAsync();
var contacts = await result.GetContactsAsync(0, contactCount);
//IReadOnlyList<StoredContact> contacts = await result.GetContactsAsync();
foreach (StoredContact item in contacts)
{
// I am not getting any contacts so this debug line is not printed !!!
Debug.WriteLine("this is not printed");
Debug.WriteLine(item.DisplayName + ":" + item.RemoteId);
}
}
catch(Exception e)
{
Debug.WriteLine("this is not printed 7");
Debug.WriteLine(e.Message);
}
}
请指出我的代码中的问题。
注意事项 我使用的是 Windows 8.1 通用应用程序模板。 我还在我的应用程序功能中添加了联系人和约会。
我觉得一切都很完美..如果我遗漏了什么,请帮助我!!
最佳答案
是的,你当然可以做到。
private async void Button_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
picker.DesiredFieldsWithContactFieldType.Add(Windows.ApplicationModel.Contacts.ContactFieldType.Email);
var contact = await picker.PickContactAsync();
if (contact == null)
return;
#if WINDOWS_APP
var button = sender as Button;
var visual = button.TransformToVisual(null);
var point = visual.TransformPoint(new Windows.Foundation.Point());
var rect = new Windows.Foundation.Rect(point, button.RenderSize);
Windows.ApplicationModel.Contacts.ContactManager.ShowContactCard(contact, rect);
#elif WINDOWS_PHONE_APP
var dialog = new Windows.UI.Popups.MessageDialog(contact.DisplayName);
await dialog.ShowAsync();
#endif
}
祝你好运!
关于windows-phone-8.1 - 在 Windows Phone 8.1 通用应用程序中访问联系人信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23735912/