This post is Day #8 in a series called the 31 Days of Windows Phone.
Yesterday I discussed how to use Launchers in a Windows Phone application. Today, we’re going to look at a similar piece of functionality for your apps, the Chooser.
What are Choosers?
Choosers are a little more complicated than Launchers, because they return data to your application, where a Launcher just gives the user a new task to accomplish. We’ll cover each of the Choosers available to you as a developer on this platform. At the end of this post, there is a downloadable project that includes code samples for each of the Choosers described here.
For each of these Choosers, you will also need to make sure that you have this statement at the top of your code-behind file. We need a reference to Microsoft.Phone.Tasks.
using Microsoft.Phone.Tasks;
For a quick look at the list of Choosers, here’s what you’ve got so far:
- CameraCaptureTask – gives your user the ability to take a picture directly from your application.
- EmailAddressChooserTask – allows your user to select an email address from their contacts to use in your application.
- PhoneNumberChooserTask – allows your user to select a phone number from their contacts to be used in your application.
- PhotoChooserTask – allows your user to select a photo from their device to be used in your application.
Using a Chooser
Each of the Choosers have their own set of properties, but after setting any of them up, you need to .Show() them to the user. To do this, you simply call the Show() method on your Chooser. The important thing to notice between these and the Launchers is that you need to create an event handler for when they make their selection. Otherwise, you won’t be able to grab the values they choose.
As an example, here’s the CameraCaptureTask:
CameraCaptureTask cct = new CameraCaptureTask(); cct.Completed += new EventHandler<PhotoResult>(cct_Completed); cct.Show();
And here’s my event handler code:
void cct_Completed(object sender, PhotoResult e) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(e.ChosenPhoto); image1.Source = bmp; }
You’ll notice that I created an event handler for when the user has taken a picture. This is so that I can get that image data into my application, and use it. When you try this in the emulator, you’ll notice that it doesn’t actually take advantage of a webcam. Instead, it creates a fake image that has a black block rotating around a white canvas. This should suffice for your testing, but I’d still recommend using actual hardware before deploying your app to the marketplace.
I linked each of the Chooser names above to their MSDN articles, where you can see the properties of each. It didn’t make much sense for me to replicate the great work they’re doing over there.
Tomorrow, we’re going to talk about some of the tools that are available to you when you’re debugging in Windows Phone 7.
Download the Code
I have included a simple project that uses each of the above Choosers in an example.

Leave a reply to devmob Cancel reply