Obtaining Email, Address or Phone Number

Windows Phone Mango now has new tasks to obtain additional information from the contacts list, such as the user’s email address, snail-mail address and phone number.

All of these work essentially in the same way: you create the chooser and show it. The contact list is displayed. You select the contact, and you get back the information in the event args. The following simple program illustrates.

Create a Windows Phone application and on MainPage.xaml create five rows in the ratio 1:1:1:4:1. Populate the first three rows with buttons and the fourth row with a TextBlock (leaving the final row empty). Here’s the complete Xaml,

Each button’s event handler will instantiate one of the choosers and set its completed event handler, and then call its Show method to launch the task. For example, the FindEmail button’s click event handler looks like this,

In each case you’ve written an event handler for the completed event. The pattern is the same for each: examine the TaskResult to ensure that nothing has gone amiss, and then extract the relevant information from the event args to display in the Results TextBlock,

When you run the application and click on one of the buttons you are taken to the contacts. If you choose a contact the relevant information is displayed on the home page.

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.

One question about the contact list : will we be able to access the contact list directly without asking the user to choose the contact itself ? I am thinking about the scenario where you loop through the list to find if the current user already have friends with a phone number present in the application database (in order to link people together).

How would one add any contacts to emulator to test it,as it has only Internet Explorer and Settings(Date, region and theme) available there? Same problem with music player and many other features – there’s no way to import any data/media to phone for testing purposes.