我想在我的windows phone中顯示所有聯繫人及其字段。 (例如:名稱,顯示名稱,暱稱等..) 我可以從我的聯繫人中獲取所有屬性。但我無法在我的聯繫人中找到'NickName'屬性。 請幫我從聯繫人獲取NickName屬性。 請找到參考此代碼,如何在Windows Phone中獲取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);
}
}
}
}
感謝和問候。
不知道我理解你的問題。我清楚地看到'Contact'類中的'Nickname'屬性。 https://msdn.microsoft.com/en-us/library/windows.applicationmodel.contacts.contact.aspx –
我想從聯繫人獲取暱稱。我沒有在聯繫人類中找到暱稱的任何屬性。我們在擴展屬性中有暱稱屬性。我可以在創建時將暱稱分配給聯繫人, StoredContact contact = null; var contactProperties = await contact.GetPropertiesAsync(); contactProperties [KnownContactProperties.Nickname] =「Matt」; 但我無法從聯繫人的Windows Phone聯繫人列表中檢索暱稱屬性。 – WinitWindowsPhone
有趣。我製作了一個快速測試應用程序,並且看到了您遇到的問題。儘管文檔指出'Contact'類具有'Nickname'屬性,但它不在那裏。我反編譯'Windows.ApplicationModel.Contacts.Contact',並且該屬性根本不存在。你不是唯一遇到這個問題的人,https://stackoverflow.com/questions/28942269/how-to-get-contacts-nickname-windows-phone-8-1,不幸的是我沒有看到解決方案。希望我可以幫助更多。 –