Saving a Contact to the Phone’s Contact List Using the SaveContactTask

,

The save contact task is used to enable a user to save a contact to the phone’s contact list. The SaveContactTask class contains 26 string properties such as FirstName, Company, and Website, which allow you to pass detailed information to the built-in Contacts app.

When the user finishes saving the contact, cancels out of the task, or an error occurs, the task’s Completed event is raised.

The sample for the SaveContactTask consists of the SaveContactTaskView page and the SaveContactTaskViewModel class.

The SaveContactTask should be defined as a field in your class, like so:

readonly SaveContactTask saveContactTask = new SaveContactTask();

Subscribe to the SaveContactTask.Completed event within your class constructor, as shown:

saveContactTask.Completed
                    += new EventHandler<SaveContactResult>(HandleCompleted);

The sample page allows the population of just some of the SaveContactTask properties (see Figure 14.25).

Image

FIGURE 14.25 SaveContactTaskView page.

When the application bar button is tapped, the Show method of the SaveContactTask launches the built-in Contacts application.

When the task returns, the Completed event handler receives a SaveContactResult object that allows you to determine whether the task completed successfully. See the following excerpt:

void HandleTaskCompleted(object sender, SaveContactResult e)
{
    if (e.Error != null)
    {
        MessageService.ShowError("Unable to save contact.");
        return;
    }

    if (e.TaskResult == TaskResult.OK)
    {
        MessageService.ShowMessage("Contact saved.");
    }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.54.63