Want to write your OWN Twitter client for WP7? It's easier than you think!
Mar
22
Written by:
Monday, March 22, 2010 9:25 PM
Check this out, my first Twitter client for WP7! Read on for the details (and link to source code so you can try it out).
Tonight I thought I would take a crack at ScottGu's Twitter client he "just whipped up" during his MIX 2010 presentation! Very bold to do that live! Well, hhhhmmm after seeing what he did, it wasn't really THAT complicated. Well, at least not once he showed EXACTLY what he did! WPF/XAML/SL and the WP7 framework make it sooooooo much easier than I had envisioned it in my mind. If you're like me and want to check this out, GO FOR IT! ScottGu GIVES you the most complicated parts so you can focus on learning the WP7 basics! Go for it! The hardest part is starting! Here's what half an hour of reading the blog and a bit of creative thinking can do for you!

The key pieces to this? Actually, it's not the Twitter URL or APIs to grab the data,
WebClient twitter = new WebClient();
twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler( twitter_DownloadStringCompleted );
twitter.DownloadStringAsync(
new Uri( string.Format( "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name={0}",
usernameTextBox.Text ) ) );
No, it's actualy the Listbox.ItemTemplate declaration in XAML.
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="100">
<Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0, 10, 8,0"/>
<StackPanel Width="370">
<TextBlock Text="{Binding UserName}" Foreground="#FFC8AB14" FontSize="28"/>
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Here are a few things I learned tonight while doing this sample:
- The WP7 emulator ignores the mouse wheel (you'll have to "click and flick" to get the listbox to scroll).
- While running your WP7 app, VS goes "drunk", what I mean is, there's a haze that goes over it to tell you, that you can't change anything while your app is running, kind of like trying to edit ASP.NET user controls while your web app is running.
- For some reason the font rendering in the emulator is terrible on my LCD, I have NO idea why? At first, I thought I didn't have the ClearType Tuner properly configured, but after redoing it for the third straight night in a row, I think it's the emulator.
- I have TERRIBLE colour coordination!
- I tried to grab the Montreal Canadiens website to brag about beating the Sens tonight, uuhhhmmmm, my team lost! DOH! I'm sure CI, SG, BC, AB, SD and SB are going to rub THAT in tomorrow!
Now that you too can build a Twitter client with VERY LITTLE EFFORT!!!!!!!! it's time to grab a coffee and get coding!
Resources
Source Code: http://www.pchenry.com:8080/svn/blog/trunk/2010/FirstTwitterClient