匯出 (0) 列印
全部展開
EN
本內容沒有您的語言版本,但有英文版本。
本主題尚未接受評分 - 為這個主題評分

How to use the save email address task for Windows Phone 8

April 14, 2014

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

Use the save email address task to enable a user to save an email address 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 save email address 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.

    SaveEmailAddressTask saveEmailAddressTask;
    
  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.

    saveEmailAddressTask = new SaveEmailAddressTask();
    saveEmailAddressTask.Completed += new EventHandler<TaskEventArgs>(saveEmailAddressTask_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 email address, but it is not required. The user can add or edit the email address before saving.

    
    
    
    saveEmailAddressTask.Email = "someone@example.com";
    
    saveEmailAddressTask.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 email was saved successfully.

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

本文對您有任何幫助嗎?
(剩餘 1500 個字元)
感謝您提供意見
Microsoft 正展開一份線上問卷調查,了解您對於 MSDN 網站的看法。 如果您選擇參加,您離開 MSDN 網站時即會顯示線上問卷調查。

您是否想要參加?
顯示:
© 2014 Microsoft. 著作權所有,並保留一切權利。