我将向您展示如何使用C#从Windows Phone 7中检索所有联系人. Contacts 类在名称空间 Microsoft.Phone.UserData 中定义,并且从 PhoneDataSharingContext 扩展而来,并提供了一些交互的方法和事件带有用户的联系数据. 公共MainPage(){InitializeComponent();联系人objContacts = new Contacts();objContacts.SearchCompleted + =新的EventHandler< ContactsSearchEventArgs>(objContacts_SearchCompleted);objContacts.SearchAsync(string.Empty,FilterKind.None,null);}void objContacts_SearchCompleted(对象发送者,ContactsSearchEventArgs e){foreach(e.Results中的var结果){lst.Add("Name:" + result.DisplayName +;电话号码:" + result.PhoneNumbers.FirstOrDefault());}} 联系人还可以使用户使用 SearchAsync 方法搜索联系人. FilterKind 确定将用于过滤的字段,例如 PhoneNumber , DisplayName 或 EmailAddress 等.无,它可以列出所有联系人.请注意,由于我目前没有配备Mango的设备,因此我使用了模拟器. 公共局部类MainPage:PhoneApplicationPage{//构造函数公共MainPage(){InitializeComponent();联系人objContacts = new Contacts();objContacts.SearchCompleted + =新的EventHandler< ContactsSearchEventArgs>(objContacts_SearchCompleted);objContacts.SearchAsync(string.Empty,FilterKind.None,null);}无效objContacts_SearchCompleted(对象发送者,ContactsSearchEventArgs e){var ContactsData =来自e.Results中的m选择新的MyContacts{DisplayName = m.DisplayName,PhoneNumber = m.PhoneNumbers.FirstOrDefault()};var MyContactsLst =来自ContactsData中的联系人通过contact.DisplayName将联系人分组为c命令由c.Key选择新的组< MyContacts>(c.Key,c);longlist1.ItemsSource = ContactsData;}}公共类MyContacts{公共字符串DisplayName {get;放;}公共ContactPhoneNumber电话号码{get;放;}} How do I grab the contact list of a windows 7 phone for use inside a win7 phone app? 解决方案 With the earlier version of the Windows Phone 7 SDK, it was only possible to retrieve the phone number or email address and a few more with the Choosers. Now, with the 7.1 Mango SDK, it is possible to retrieve more information from the contact, like Address, DisplayName, EmailAddresses etc.I will show you how to retrieve all contacts from Windows Phone 7 using C#.The Contacts Class is defined in the namespace Microsoft.Phone.UserData and extends from PhoneDataSharingContext and provides a few methods and events for interacting with a user’s contact data.public MainPage(){InitializeComponent();Contacts objContacts = new Contacts();objContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(objContacts_SearchCompleted);objContacts.SearchAsync(string.Empty, FilterKind.None, null);}void objContacts_SearchCompleted(object sender, ContactsSearchEventArgs e){foreach (var result in e.Results){lst.Add("Name : " + result.DisplayName + " ; Phone Number : " + result.PhoneNumbers.FirstOrDefault());}}Contacts can also enable the user to search for the contact with the SearchAsync method. The FilterKind determines the field that will be used for filtering like PhoneNumber, DisplayName or EmailAddress etc. When it is None, it can list all the contacts.Note that I have used the emulator since I don't have the device with Mango currently.public partial class MainPage : PhoneApplicationPage{// Constructorpublic MainPage(){InitializeComponent();Contacts objContacts = new Contacts();objContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(objContacts_SearchCompleted);objContacts.SearchAsync(string.Empty, FilterKind.None, null);}void objContacts_SearchCompleted(object sender, ContactsSearchEventArgs e){var ContactsData = from m in e.Resultsselect new MyContacts{DisplayName = m.DisplayName,PhoneNumber = m.PhoneNumbers.FirstOrDefault()};var MyContactsLst = from contact in ContactsDatagroup contact by contact.DisplayName into corderby c.Keyselect new Group<MyContacts>(c.Key, c);longlist1.ItemsSource = ContactsData;}}public class MyContacts{public string DisplayName { get; set; }public ContactPhoneNumber PhoneNumber { get; set; }} 这篇关于将Windows 7手机的联系人列表集成到应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 05:53