如何在Windows Phone中获取已保存联系人的昵称属性

本文关键字:联系人 保存 属性 获取 Windows Phone | 更新日期: 2023-09-27 17:54:46

我想显示我的windows手机中的所有联系人及其字段。(例如:名称、DisplayName、昵称等)我可以从我的联系人中获得所有属性。但是我无法在我的联系人中找到"昵称"属性。请帮助我从联系人获得昵称属性。请找到这个代码供参考,

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

如何在Windows Phone中获取已保存联系人的昵称属性

我最近正在开发一个Windows Phone 8.1运行时应用程序,也遇到了同样的问题。

我刚刚在这里回答了一个类似的老帖子:如何获取联系人昵称Windows Phone 8.1 - Stack Overflow

Contact类的Nickname属性似乎已经被Microsoft文档化了,但还没有实现到Visual Studio中供其他开发人员使用。

你可以在这里看到Contact类的所有属性:联系人类- Windows应用程序开发

和昵称属性的细节在这里:接触。昵称|昵称属性- Windows应用开发

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

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