为什么人脉应用不显示联系人/不允许我选择联系人? [英] Why does the People app show no contacts / doesn't allow me to pick contacts?

查看:21
本文介绍了为什么人脉应用不显示联系人/不允许我选择联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试允许用户通过这种方式从人脉"应用中选择联系人:

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");
}

People 应用确实被调用,但看起来像这样:

The People app does get invoked, but it looks like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~人v

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ People v

出了点问题,此应用目前无法选择联系人.

Something went wrong, and this app can't pick contacts right now.

再次尝试选择应用.

            | 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?

推荐答案

我尝试了您的代码,它按预期打开了联系人选择器.只是为了测试,尝试使用单个按钮创建一个新应用程序,该按钮从其 Click 事件处理程序调用您的方法,就像我所做的那样.

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.

虽然我在做:您可能想要稍微更改代码 - 要实际获取电子邮件地址,请将 contact.Emails[0].ToString() 替换为 contact.Emails[0].Value:

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.

这篇关于为什么人脉应用不显示联系人/不允许我选择联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆