Silverlight Sample Application – Part 3

In this series blog post I’m continuing to talk about the sample Silverlight application that was used in the Ottawa and Toronto code camps this year.

You can get the source to the application on CodePlex.

The purpose of the application (other than to show people how to get started with Silverlight application development), was to be an IT event information application.  The third ‘page’ (yes – I’ll get to the second page in the next post) of the application shows tweets about the event.

Since the Ottawa and Toronto code camps happen in April and May, here’s the same page set up to show tweets tagged with #teched for this month’s Microsoft TechEd confeference.

20100613 tweets

To get the data, we can use one of the great methods available in Silverlight to get data – the WebClient class.  This class is often used when you are connecting to a RESTful service which is documented somewhere but is not self-described with metadata (like many SOAP/OData web service where Add Service Reference in Visual Studio can often be used to create a proxy class).

All network data access in Silveright must be asynchronous to avoid the UI from freezing up.

We create out WebClient, setup a completion event handler and start an asynchronous download of a string using the Twitter Search API.

20100613 tweet behind

Once the completion event fires, we make sure there’s no error and then pass off processing of the received string to a utility function to get back objects we can bind to on our ListBox.

The Twitter Search API response format is document (or discoverable at least) so we set up a class to hold the items of a tweet we are interested in, and use LINQ to XML code to pull out the appropriate XML elements from the Twitter API Atom feed.

 20100613 tweet util

It’s that simple when you get the hang of LINQ to XML.  It’s a must learn for the modern .NET developer.

With objects to bind to we need to create a DataTemplate for our ListBox ItemTemplate (the template used every time the visual tree for a new item needs to be generated).

20100613 tweet xaml

And there you have it.  It’s surprising there aren’t even more Twitter Clients coming out of the woodwork.

Check out other series blog posts for more information about this sample application.