Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to use the save phone number task for Windows Phone 8

August 19, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

Use the save phone number task to enable a user to save a phone number from your application. This task launches the Contacts application.

By using Choosers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

To use the phone number task

  1. Add the following statement to your code.

    using Microsoft.Phone.Tasks;
    
  2. Declare the task object. It must have page scope, so declare it in your page before the constructor.

    SavePhoneNumberTask savePhoneNumberTask;
    
  3. Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.

    savePhoneNumberTask = new SavePhoneNumberTask();
    savePhoneNumberTask.Completed += new EventHandler<TaskEventArgs>(savePhoneNumberTask_Completed);
    
  4. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

    You can pre-populate the phone number, but it is not required. The user can add or edit the phone number before saving.

    
    
    
    savePhoneNumberTask.PhoneNumber = "2065550123";
    
    savePhoneNumberTask.Show();
    
    
    
    
    
    
    
  5. Add the code for the completed event handler to your page. This code runs after the user completes the task. You can check to see whether the phone number was saved successfully.

    void savePhoneNumberTask_Completed(object sender, TaskEventArgs e)
    {
        switch (e.TaskResult)
        {
            //Logic for when the number was saved successfully
            case TaskResult.OK:
                MessageBox.Show("Phone number saved.");
                break;
    
            //Logic for when the task was cancelled by the user
            case TaskResult.Cancel:
                MessageBox.Show("Save cancelled.");
                break;
    
            //Logic for when the number could not be saved
            case TaskResult.None:
                MessageBox.Show("Phone number could not be saved.");
                break;
        }
    }
    

Show:
© 2014 Microsoft