Listing All Phone Contacts in Windows Phone 8
In this post we would see how to list down all contacts available in your Windows Phone 8 device programmatically.
To proceed; create a sample Windows Phone application with version as 8.0
Go to the Capabilities tab and select ID_CAP_CONTACTS
Ideally we would perform the operation in the ViewModel, here is how we would do it.
A property of type ObservableCollection<Contact>
Then we would have a method, to perform the search operation on empty string. This is the only way till now to list all the contacts from the phone.
As you see above, the contacts class object is created and then we are subscribing to the event SearchCompleted, and finally the Search method, where we are passing the required parameters.
And of course we would have the link between the View and the ViewModel.
Let’s call this method in the constructor and run the application let’s see whether we are able to get the list of contacts.
We will not get the list in the first run because the account to the people application is not linked. Or there are no contacts available in the phone.
Let’s map the account with the People app.
Select “set up account”
Then, choose your account type. In this sample I would be using Google.
Choose what to sync, in our case we would choose the 2nd option.
After, everything is synced; you would have screen something similar to the following.
Now, if we run the application; we would definitely get some contacts.
Now, we would display it in our page.
The following ListBox, would display DisplayName and PhoneNumbers from the contact. As PhoneNumbers is a collection; we have used an ItemsControl in the ItemTemplate.
Let’s see how it looks!
So, we have successfully listed all contacts from the phone.
Hope this article helps. Thanks for reading.
Source code: Click Here