code first, ask questions later

Windows Phone (Mango) Contact Chooser Task

When creating the amazing, incredible and life changing app for managing money you borrow and lend Metrowe I was pretty annoyed to discover that in the Mango SDK there are choosers for selecting emails: EmailAddressChooserTask and phone numbers: PhoneNumberChooserTask but not just plain selecting a contact. The problem with the other choosers is the email address will exclude contacts without an email and similarly the phone number chooser and phone numbers. After much complaining decided to develop my own contact chooser (quite closely based off this french one) matching the OS version as closely as possible. This is what it ended up looking like:

private void button1_Click(object sender, RoutedEventArgs e)
{
    var contactChooser = new ContactChooserTask();
    contactChooser.OnSelected += new EventHandler<ContactChooserEventArgs>(contactChooser_OnSelected);
    contactChooser.Show();
}

void contactChooser_OnSelected(object sender, ContactChooserEventArgs e)
{
    MessageBox.Show(e.Contact.DisplayName);
}

Under the covers it is a bit of a different story. The display relies on the Silverlight Toolkit’s LongListSelector (which is awesome) and uses code pretty similar to that described by my good friend Benjii in his post: How to Use the Long List Selector for Windows Phone Mango. The code to encapsulate the page is kind of a mish mash of code adapted(/stolen) from the source of the Coding4Fun toolkit (also awesome). That said it seems to work well in my app and in my very limited testing.

The code for the library lives on github at lukencode/ContactChooser and is free and open source fork it, try it out, tell me how I suck then submit a pull request fixing the aforementioned suck! A couple of things that would be cool to see added would be some nice transition animations in and out and some more control over how the chooser looks.

blog comments powered by Disqus