This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on

Tuesday, March 23, 2010

Windows Phone 7 Series Development – Allowing the User to Choose a Photo

I am using the WP7 SDK from March 2010 at the time of this post.

I’ve been working on the SDK the last few days and am really enjoying it. I’ve hit a few roadblock in the ‘tasks’ department and am hoping to find a workable solution soon.

At this time, it does not appear that the emulator is ready for some types of application development and testing, specifically related to work in the Microsoft.Phone.Tasks namespace.

A little fun, first


I think it would be hilarious if everyone downloaded the emulator for Windows Phone 7 Series and started hitting Apple’s site from IE.

I don’t think they’d care, but it would still be funny.

MSDN Struggles

So, we have a few things to work from if we want to get the user to pick a photo. Say you’ve got an application that would allow them to send a photo to a friend or upload it to a service on the cloud.

The first thing they’ll need to do, obviously, is to pick the photo they want to work with. This actually looks like a trivial task.

In the Microsoft.Phone.Tasks namespace we have a series of helpers that give the user a consistent “Windows Phone” look and feel from within our applications. Here are some examples:

  • BingMapsTask
  • CameraCaptureTask
  • EmailAddressChooserTask
  • EmailComposeTask
  • PhoneCallTask
  • PhoneNumberChooserTask
  • PhotoChooserTask
  • SaveEmailAddressTask
  • SavePhoneNumberAddressTask
  • SearchTask
  • SMSComposeTask

We’re going to be able to offer a deep level of integration with the phone experience. Unfortunately, we’re working in a bit of a void right now.

The documentation suggests that, when executed, these tasks will return there results on the Page’s OnChooserReturn event. The signature is simply:

void OnChooserReturn(object sender, EventArgs e)

The single entry point concept here (all task results will come in on the same event handler) suggests that we’re going to want to use the Rx (Reactive) framework to sort out the details.

But how do we get at our result?

imageMSDN lists a ChooserEventArgs object that gives us access to the result. This is a generic class, with the task-specific result type defining the result. But how do we pull it?

There are no examples at this point, so I can only assume we’re going to cast it from the EventArgs we get in OnChooserReturn. We’ll use reflection to test (likely, this is where we’ll put Rx to work) then handle the result as appropriate.

As you can see from the emulator screen shot, I can’t go any further to test, explore or prove this as cannot execute the Tasks listed above with the current tools. Instead, we are presented with the following COMException:

The drive cannot locate a specific area or track on the disk.

The PhotoResult class (returned from the CameraCaptureTask and the PhotoChooserTask) will be the type I funnel in on when this functionality is lit up.

The Good and the Bad

I’m loving this direction. The Rx Framework is all about applications that live and respond to an environment and doing that asynchronously. Funnelling the results of environment actions by the user through a single event on a page allow us to behave that way as well.

Because we get access to the resultant object by overriding the event handler on the page, we will be able to have each page in our application respond differently – in context – when the event fires. I think this is a fairly clean approach and hopefully encourage developers to design specific contexts for their applications.

There are two negatives from my perspective right now:

  1. Lack of code samples – this one will work itself out. As the community jumps on board we’ll see the samples popping up. I hope I can contribute in this area, too. MSDN will also move towards a more complete state if Microsoft follows through on their commitment to developers in this space.
  2. Lack of emulator support – this will be a big pile of suck if it doesn’t get implemented. I’m hopeful that there will be an integrated photo store, or a way to push photos to the device in such a way that the emulator sees them as user photos. Also, emulated camera support would be great: let me specify a directory on the computer with photos in it, then choose a random one to return when I ‘take’ a photo in the emulator.

Early Goods

As is always the case when you get in early, the bits are tasty but not filling.

I highly encourage developers to get in on the scene here and push around the SDK.

And PLEASE, if you find out how to get the tasks working in the short term (in the emulator) let me know!


  1. hey, did you ever end up figuring this out? thanks!

  2. Sorry Marta, not yet. I spoke with a couple folks on the development team and they realize this is a huge drawback.

    The suggested workaround is to just sub in a random response, which is okay for testing (I had mine calling a web service).