The previous was the unveiling of self-learning Windows Phone 7, creating the first application http://www.cnblogs.com/tongyi/archive/2012/02/18/WindowsPhone1.html.
Windows Phone 7 has a relatively high security of Self-powered mobile phones. Unlike the home-made stockade machine, it will send fee deduction text messages without your knowledge. Most WP7 tasks need to be executed after confirmation by the user. Today, we will explain the basic Task calling Syntax of Windows Phone and present its results.
Namespace to be imported:
Using Microsoft. Phone. Tasks;
Using System. Windows. Media. Imaging;
Using System. Diagnostics;
1. tasks that do not need to return values
1. Call the Task code:
PhoneCallTask call = new PhoneCallTask ();
Call. PhoneNumber = "10086 ";
Call. DisplayName = "China Mobile ";
Call. Show ();
Effect:
You can also enter the phone number in the text box.
2. Short Message task
SmsComposeTask s = new SmsComposeTask ();
S. To = "'10086 ";
S. Body = "YE ";
S. Show ();
Effect:
Of course, you can insert other text or images into the content, and you need to confirm before sending.
3. Task
EmailComposeTask email = new EmailComposeTask ();
Email. To = "136138641@qq.com ";
Email. Subject = "Email Subject ";
Email. Body = "Windows Phone 7 send email ";
Email. Show ();
A Windows live mailbox is required for sending emails.
4. Open the browser's Task
WebBrowserTask browser = new WebBrowserTask ();
Browser. URL = "http://www.cnblogs.com ";
Browser. Show ();
Effect:
5. // search tasks
SearchTask search = new SearchTask ();
Search. SearchQuery = "wp7"; // search Keyword
Search. Show (); // use Microsoft's bing search
6. Media repository Task
MediaPlayerLauncher mpl = new MediaPlayerLauncher ();
Mpl. Controls = MediaPlaybackControls. All;
Mpl. Location = MediaLocationType. Install;
Mpl. Media = new Uri ("momeryy", UriKind. Relative); // This is a sample. Please change it as your needs.
Mpl. Show ();
Not very nice
Summary: Taking the preceding Task as an example, you will find that all tasks have the Show () method for calling and execution. The code is encapsulated like the C # code, which is very easy to call, microsoft is powerful.
Ii. TaskResult returned
1. Save the contact Task
Private void button3_Click (object sender, RoutedEventArgs e)
{
// Save the contact
SavePhoneNumberTask savePhoneNumber = new SavePhoneNumberTask ();
SavePhoneNumber. PhoneNumber = "10086 ";
SavePhoneNumber. Completed + = new EventHandler <TaskEventArgs> (savePhoneNumber_Completed); // Completed binding event
SavePhoneNumber. Show (); // The Show () method is also required.
}
Void savePhoneNumber_Completed (object sender, TaskEventArgs e)
{
If (e. TaskResult = TaskResult. OK) // e event judgment, TaskResult Enumeration
{
MessageBox. Show ("saved successfully ");
}
}
2. photographing Task
<Image Height = "230" HorizontalAlignment = "Left" Margin = "52,228, 366 "Name =" image1 "Stretch =" Fill "verticalignment =" Top "Width =" "/>
Add an image control to display images
CameraCaptureTask cameraCapture = new CameraCaptureTask ();
CameraCapture. Completed + = new EventHandler <PhotoResult> (cameraCapture_Completed );
CameraCapture. Show ();
Void cameraCapture_Completed (object sender, PhotoResult e)
{
If (e. TaskResult = TaskResult. OK)
{
BitmapImage image = new BitmapImage ();
Image. SetSource (e. ChosenPhoto); // e. ChosenPhoto is a Stream
Image1.Source = image;
}
}
Effect:
Because there is no camera, the simulator is black because it is ugly.
3. Select an image Task
PhotoChooserTask photoChooser = new PhotoChooserTask ();
PhotoChooser. PixelHeight = 100; // capture the Image Height
PhotoChooser. PixelWidth = 100; // specifies the width of the captured image.
PhotoChooser. ShowCamera = true;
PhotoChooser. Completed + = new EventHandler <PhotoResult> (photoChooser_Completed );
PhotoChooser. Show ();
Void photoChooser_Completed (object sender, PhotoResult e)
{
If (e. TaskResult = TaskResult. OK)
{
BitmapImage image = new BitmapImage ();
Image. SetSource (e. ChosenPhoto );
Image1.Source = image;
}
Debug. WriteLine ("FileName:" + e. OriginalFileName + "Length:" + e. OriginalFileName. Length + "bytes ");
}
Effect
Conclusion: all the preceding tasks have TaskResult, which is easy to call.
Summary: there are many tasks provided by Windows Phone. We will introduce them here today. The Task is very simple and basic, so you don't need to explain it too much. Continue...