This article is about Windows Phone 7 development on the 31st day"8th Day of the series.
Yesterday I introduced how to use Windows PhoneProgramUsing the starter. Today, let's look at the functions similar to the starter in the program, selector.
What is a selector?
Selectors are a little more complex than starters because they need to bring data back into the program, while starters only allow users to complete a task. We will explain each available selector on this platform. At the end of this article, I provide a downloadable selector that contains all the describedCodeExample.
For each selector, make sure that the following statements are included in the file after the code. We need to reference the Microsoft. Phone. Tasks namespace.
Using Microsoft. Phone. tasks;
The following lists available selectors:
- Cameracapturetask-Provides users with the function of taking photos directly in the program.
- Emailaddresschoosertask-In the program, you can select an email address from the contact.
- Phonenumberchoosertask-In the program, you can select a phone number from the contact.
- Photochoosertask-In the program, you can select a photo from the device.
Use Selector
Each selector has its own attributes, but after setting it, you need to call the show method to display it to the user. You can use the show method in the selector. Among the many selectors, remember that you need to create an event handler after the user makes the choice. Otherwise, you will not be able to capture the data they selected.
As an example, let's take a look at cameracapturetask:
Cameracapturetask CCT = New Cameracapturetask ();
CCT. Completed + = New Eventhandler < Photoresult > (Cct_completed );
CCT. Show ();
Here is the event handler I added:
Void Cct_completed ( Object Sender, photoresult E)
{
Bitmapimage BMP = New Bitmapimage ();
BMP. setsource (E. chosenphoto );
Image1.source = BMP;
}
You will notice that I created an event handler when taking a photo of the user. This is how I obtain and use photo data in the program. When you test it in a simulator, you will see that it does not actually use cameras. Instead, a fake image with a black rotation in the white canvas is created. This should meet your test requirements, but I suggest you test it with a real device before uploading your program to marketplace.
I have linked the names of each selector to the corresponding msdnArticle, Where you can see all the attributes. So I am not doing this kind of copy work here. Tomorrow we will discuss some useful tools for you when debugging the Windows Phone 7 Application.
Download Sample Code
This example contains all the selectors mentioned above.
Original article address:
Http://www.jeffblankenburg.com/post/31-Days-of-Windows-Phone-7c-Day-8-Choosers.aspx
if you like my article, click "recommended", thank you!