如何从Windows Phone中的已保存联系人获取NickName属性

时间:2015-06-09 15:20:24

标签: c# windows-phone-8.1

我想用我们的字段显示我的Windows手机中的所有联系人。 (例如:Name,DisplayName,NickName等..) 我能够从我的联系人那里获得所有房产。但我无法找到NickName'在我的联系中的财产。 请帮我从联系人那里获取NickName财产。 请找到此代码以供参考,



using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Contacts;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Phone.PersonalInformation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641

namespace ConatctsTestApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: Prepare page for display here.

            // TODO: If your application contains multiple pages, ensure that you are
            // handling the hardware Back button by registering for the
            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
            // If you are using the NavigationHelper provided by some templates,
            // this event is handled for you.
        }
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string searchText = "";
            Windows.ApplicationModel.Contacts.ContactStore contactStore = await ContactManager.RequestStoreAsync();

            IReadOnlyList<Contact> contacts = null;

            if (String.IsNullOrEmpty(searchText))
            {
                // Find all contacts
                contacts = await contactStore.FindContactsAsync();
            }
            else
            {
                // Find contacts based on a search string
                contacts = await contactStore.FindContactsAsync(searchText);
            }

            for (int c = 0; c < contacts.Count; c++)
            {                
                    string impdate = "";

                    for (int i = 0; i < contacts[c].ImportantDates.Count; i++)
                    {
                        impdate = impdate + contacts[c].DisplayName + "\n";
                        ContactDateKind kind = contacts[c].ImportantDates[i].Kind;

                        impdate = impdate + kind.ToString() + "\n";
                        impdate = impdate + (contacts[c].ImportantDates[i].Day.Value + 1).ToString() +
                                      "." + contacts[c].ImportantDates[i].Month.Value.ToString() +
                                      "." + contacts[c].ImportantDates[i].Year.Value.ToString();
                        impdate = impdate + "\n";
                    }
                    for (int i = 0; i < contacts[c].Websites.Count; i++)
                    {
                        //Count 0
                    }
                    for (int i = 0; i < contacts[c].Addresses.Count; i++)
                    {
                        string addressKind = contacts[c].Addresses[i].Kind.ToString();
                    }                
                //MessageBox.Show(impdate);
            }
        }
    }
}
&#13;
&#13;
&#13;

谢谢和问候。

1 个答案:

答案 0 :(得分:0)

我最近在使用Windows Phone 8.1 Runtime应用程序,并且遇到了同样的问题。

我刚才在这里回答了一篇类似的老帖子: How to get Contact's Nickname Windows Phone 8.1 - Stack Overflow

似乎Microsoft已记录了Contact类的Nickname属性,但尚未在Visual Studio中实现,以供其他开发人员使用。

您可以在此处查看Contact类的所有属性: Contact class - Windows app development

这里有Nickname属性的详细信息: Contact.Nickname | nickname property - Windows app development

检查属性页面。一条消息说它没有发布,而且要求是Windows 10。

用户可以在People应用程序中输入昵称似乎很奇怪,但我们和其他开发人员不能在我们自己的应用程序中使用它。我想这就是现在使用Windows Phone 8.1自定义应用程序的方式。