user3605064
user3605064

Reputation: 11

VS Windows Phone Lookup and Select Contact

How can I make a drop down box for someone to select one of their contacts from? I am using Visual Studio Express 2012 for Windows Phone.

Thanks.

Upvotes: 2

Views: 24

Answers (1)

DotNetRussell
DotNetRussell

Reputation: 9857

This is built in functionality. Use the PhoneNumberChooserTask

//When you see the red underline hold (control + period) 
// OR you can just add the using yourself at the top of the page
//using Microsoft.Phone.Tasks;
PhoneNumberChooserTask pnct= new PhoneNumberChooserTask(); 

pnct.Completed += new EventHandler<PhoneNumberResult>(pnct_Completed);

Once you have it initialized you can do a show

pnct.Show();

Then in the completed event just extract what you need.

void pnct_Completed(object sender, PhoneNumberResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        MessageBox.Show("The phone number for " + e.DisplayName + " is " + e.PhoneNumber);

        //Code to start a new call using the retrieved phone number.
        //PhoneCallTask phoneCallTask = new PhoneCallTask();
        //phoneCallTask.DisplayName = e.DisplayName;
        //phoneCallTask.PhoneNumber = e.PhoneNumber;
        //phoneCallTask.Show();
    }
}

This is the suggested way of doing what you are asking because it keeps the environment consistent for the user. A consistent user environment means they will be happier with your app.

The reference for this answer can be found on this MSDN article

Upvotes: 1

Related Questions