Description of various tasks in Windows Phone 7 (starters and selectors)

Source: Internet
Author: User

I. Common Tasks

All tasks have the show method, and call the show method to start the task. After the task is completed, the application is generally returned. All tasks (tasks) are not automatically started and need to be manually clicked, this is windowphone7 based on security considerations to prevent leakage of fees and other issues.

Here we need to add the following namespace:

using Microsoft.Phone.Tasks;

1.1Smscomposetask

Start the text message sending task. You can set the recipient's number and text message content through the to and body attributes. After setting the to and body content, you need to call the show method, the text message sending interface is displayed.

Sample Code:

using Microsoft.Phone.Tasks;
1.1 SmsComposeTask

To start the task of sending SMS, you can set the other party's number and the content of the SMS through the two properties of To and Body. After setting the content of To and Body, you need to call the Show method to display the interface for sending SMS.

Sample code:

private void Sendbutton_Click (object sender, RoutedEventArgs e)
        {
            SmsComposeTask sendms = new SmsComposeTask ();
            sendms.To = "10086";
            sendms.Body = "Call Charge Query";
            sendms.Show ();
        }
1.2 EmailComposeTask

    Start sending email service, the same can be set by To, Subject, Body, CC properties to set the recipient, title, content and CC.

Sample code:

 private void Sendbutton_Click (object sender, RoutedEventArgs e)
        {
            EmailComposeTask sendemail = new EmailComposeTask ();

            sendemail.To = "972103830@qq.com";

            sendemail.Subject = "Hello";

            sendemail.Body = "Hello, this is ... text message to you!";

            sendemail.Show ();
        }
1.3 WebBrowserTask

      To start the browser service, you can set the URL path (URL means absolute path) or Uri (relative path).

code show as below:

private void Sendbutton_Click (object sender, RoutedEventArgs e)
        {
            WebBrowserTask webtask = new WebBrowserTask ();
            webtask.URL = "http://www.baidu.com";
            webtask.Show ();
        }
1.4 PhoneCallTask

      Start the windows phone calling service, you can set the contact name and contact phone number by setting DisplayName and PhoneNumber.

Sample code:

 private void Sendbutton_Click (object sender, RoutedEventArgs e)
        {
            PhoneCallTask phoneTask = new PhoneCallTask ();
            phoneTask.DisplayName = "China Mobile";
            phoneTask.PhoneNumber = "10086";
            phoneTask.Show ();
        }
Some Tasks will also return an execution result parameter. These tasks are generally inherited from ChooserBase and contain a Completed event that listens to the task. The execution result can be obtained from the event parameter e. All task event parameters e contain a TaskResult attribute , And there are three values, that is, three cases of task processing: Ok. Indicates that the task was successfully executed, Cancel. Indicates that the task was canceled, and Erro. Indicates that an error occurred during the execution process. Let's take a look at the specific task name below:

1.5 SavePhoneNumberTask

      For the task of saving phone numbers, you can set the number of saved phone numbers by setting the PhoneNumber property. Note that the contact name of the phone number cannot be set here, it needs to be added manually after starting the task.

Sample code:

 private void Sendbutton_Click (object sender, RoutedEventArgs e)
        {
            SavePhoneNumberTask savephonenum = new SavePhoneNumberTask ();
            savephonenum.PhoneNumber = "15040057978";
            savephonenum.Completed + = new EventHandler <TaskEventArgs> (savephonenum_Completed);
            savephonenum.Show ();
        }

        void savephonenum_Completed (object sender, TaskEventArgs e)
        {
            if (e.Error! = null)
            {
                MessageBox.Show ("Error");
            }
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show ("Save successfully!");
            }
            if (e.TaskResult == TaskResult.Cancel)
            {
                MessageBox.Show ("The task has been cancelled!");
            }
        }
1.6 PhoneNumberChooserTask

      The task used to select the phone number, where the event parameter e contains a PhoneNumber attribute, which can be used to obtain the selected number.

Sample code:

private void button1_Click (object sender, RoutedEventArgs e)
        {
            PhoneNumberChooserTask ChooserphoneNum = new PhoneNumberChooserTask ();
            ChooserphoneNum.Completed + = new EventHandler <PhoneNumberResult> (ChooserphoneNum_Completed);
            ChooserphoneNum.Show ();
        }

        void ChooserphoneNum_Completed (object sender, PhoneNumberResult e)
        {
            if (e.Error == null && e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show (e.PhoneNumber);
            }
        }
1.7 CameraCaptureTask

       The task used to take pictures, where the event parameter e contains a ChosenPhoto attribute, which can be used to obtain the picture taken.

Sample code:

 private void TakePhotobutton_Click (object sender, RoutedEventArgs e)
        {
            CameraCaptureTask takePhoto = new CameraCaptureTask ();
            takePhoto.Completed + = new EventHandler <PhotoResult> (takePhoto_Completed);
            takePhoto.Show ();
        }

        void takePhoto_Completed (object sender, PhotoResult e)
        {
            if (e.Error == null && e.TaskResult == TaskResult.OK)
            {
                BitmapImage bitmap = new BitmapImage (); // Define the picture of the stream data format
                bitmap.SetSource (e.ChosenPhoto); // Set streaming data source
                image1.Source = bitmap; // Assign stream data image to Image
            }
        }
1.8 PhotoChooserTask

The task used to select pictures contains the following attributes:

PixelWidth: Set the width of the selected picture, the unit is pixel

PixelHeight: set the height of the selected picture, the unit is pixel

ShowCamera: Set whether to allow taking pictures, true OR false.

If the selected picture is larger than the size we set (ie PixelWidth and PixelHeight), it will be automatically cropped to the size of the picture we set.

Similarly, the event parameter e also contains the ChosenPhoto attribute, which is the same as the previous CameraCaptureTask.

Sample code:

  private void ChoosePhotoButton_Click (object sender, RoutedEventArgs e)
        {
            PhotoChooserTask choosephoto = new PhotoChooserTask ();
            choosephoto.PixelWidth = 200;
            choosephoto.PixelHeight = 200;
            choosephoto.ShowCamera = true;
choosephoto.Completed + = new EventHandler <PhotoResult> (choosephoto_Completed);
            choosephoto.Show ();
        }

        void choosephoto_Completed (object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK && e.Error! = null)
            {
                BitmapImage bitimage = new BitmapImage ();
                bitimage.SetSource (e.ChosenPhoto);
                image1.Source = bitimage;
            }
        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.