Click here to Skip to main content
16,016,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to Windows Mobile. Developing a Windows phone Universal store application.
When my app starts i'm supposed to pick the Contact name and Phone Number available in the Phone.

Could any one guide me through a correct tutorial.

I did the following got all contact Names in ListView.
C#
var contactStore = await ContactManager.RequestStoreAsync();
var contacts = await contactStore.FindContactsAsync();

foreach (var Item in contacts)
{
    lstContact.Items.Add(Item.DisplayName);
}

But how do i get the result in following format

Name 1
Phone Number

Name 2
Phone Number

:
:

Name n
Phone Number

Request for help.
Posted
Updated 16-Jun-15 20:46pm
v3

1 solution

Hi,

As far as I've seen on MSDN, contactStore.FindContactsAsync() returns you a list of contacts [^].
In the foreach loop you can retrieve the phone numbers by using Item.phones[^] which returns a list of ContactPhones[^] and for the name you can use Item.Name[^] which returns a string.

Anyway, it's very important for you to look at this page to get further information: https://msdn.microsoft.com/en-us/library/windows.applicationmodel.contacts.contact.aspx[^]

Your results are displayed like that in the listbox because there is a hidden call to the method ToString when an object is added to the Listbox if a good DataTemplate is missing, so you get the String representation of a ContactPhone object.

I hope this helps.

LG
 
Share this answer
 
v2
Comments
LLLLGGGG 15-Jun-15 8:58am    
PS: always look up things on MSDN when you're stuck: it's a very handy site and it solved whatever error/doubt you can face about a class/property/methoda and so forth.
Hari-CodeBlogger 17-Jun-15 3:15am    
When i use Item.Phones , it prints "Windows.Foundation.Collection.NonNullVector" ., Is this because i use the emulator.?
LLLLGGGG 17-Jun-15 3:19am    
That is because it is a vector. Access to an item of tne vector to see a phone number. Do Item.Phones[0].Number. It should work... You can also use a foreach loop and access all the phone numbers in the collection.
Hari-CodeBlogger 17-Jun-15 3:28am    
Thank You so much..
LLLLGGGG 17-Jun-15 4:19am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900