Reputation: 10297
I'm trying to allow the user to select a contact from the People app this way:
private async Task<System.Collections.Generic.KeyValuePair<string, string>> SelectAContactForASlot()
{
KeyValuePair<string, string> kvp; // = new KeyValuePair<string, string>();
var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
contactPicker.CommitButtonText = "Select";
var contact = await contactPicker.PickSingleContactAsync();
if (contact != null)
{
kvp = new KeyValuePair<string, string>(contact.Name, contact.Emails[0].ToString());
return kvp;
}
return kvp = new KeyValuePair<string, string>("No Name found", "No email found");
}
The People app does get invoked, but it looks like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ People v
Something went wrong, and this app can't pick contacts right now.
Try selecting the app again.
| Select | | Cancel |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I added a couple of contacts yesterday, so it does contain contacts. Is there something wrong with my code, or how else can I solve this problem?
Upvotes: 0
Views: 475
Reputation: 17865
I tried your code and it opened the contact picker as expected. Just for a test, try creating a new application with a single button which calls your method from its Click
event handler, like I did.
Also, you might want to freshly logon / reboot to your machine if the problem persists. I know I had similar problems with the sharing functionality in the past - after handling it wrong in my code, even correct code didn't work any more until a reboot.
While I'm at it: you might want to change your code a little bit - to actually get the email address, replace contact.Emails[0].ToString()
with contact.Emails[0].Value
:
private async Task<System.Collections.Generic.KeyValuePair<string, string>> SelectAContactForASlot()
{
KeyValuePair<string, string> kvp; // = new KeyValuePair<string, string>();
var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
contactPicker.CommitButtonText = "Select";
var contact = await contactPicker.PickSingleContactAsync();
if (contact != null)
{
kvp = new KeyValuePair<string, string>(contact.Name, contact.Emails[0].Value);
return kvp;
}
return kvp = new KeyValuePair<string, string>("No Name found", "No email found");
}
Don't forget to get handle the case when the contact doesn't have any email addresses, as well.
Upvotes: 1