Skip Ribbon Commands
Skip to main content
Navigate Up
Sign In
Brian's Blog > Posts > Getting the Most Out of ScottGu's Silverlight 2.0 Overview
March 25
Getting the Most Out of ScottGu's Silverlight 2.0 Overview

I'm sure you saw the Silverlight 2 Overview that Scott Guthrie posted a little while back at his site.  The small Digg client he wrote is a great walkthru if you're looking for something to get you started with Silverlight 2.  It covers a lot of basic Silverlight concepts and types as well as spreading the code between XAML and the code-behind.  He also posted the working code sample on the site with his eight part overview. 

I like to write the code as I follow along with things like this and I had a few problems getting my code sample working.  I fixed some of the errors by looking at Scott's provided code sample and others looking through the comments at the site.  In the comments, I also saw there were a lot similar problems and a few working answers.  Some of them helped me and most of the fixes were minor tweaks so I made notes as I went to try to collect all the fixes in one place.  Here they are in case you need them.

  • Overall
    • I try not to complain about free help but pictures of code stink.  You can't cut and paste code from a picture and trying to type it produces errors in translation.  I missed the question mark in the Digg query string and spent a few minutes staring at the code trying to figure out why it didn't work.
    • Scott changes the DataGrid to a List in Part 5 of the tutorial.  The overview makes note of it but it can be pretty confusing if you're not looking ahead.  Just stick with the grid and change it in Part 5.
    • Scott works over the sample a little bit in Part 8 to make it work with WPF instead of Silverlight.  That's why the code in the downloaded sample may not match what you're staring at prior to Part 8.
  • PART 2
    • The searchbutton and related click event are renamed appropriately between Part 1 and Part 2.  It doesn't make a difference in functionality but you may want to rename them for sanity.
  • PART 3
    • I believe I had to add a reference to System.Linq and System.XML for the code to compile.
    • To use the DataGrid as shown, you'll need to add a namespace reference for the Silverlight DataGrid to the top of Page.xaml.  Add the following line to the namespace attribute:
      • xmlns:Data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    • When you query Digg, the topic you are querying for has to really exist at Digg or you'll get a "Download Failure" error.  Try "basketball" as your search.
  • PART 4
    • When you start moving all of your attributes out to styles as shown in the code sample, you'll have to set the TargetType for the style or you'll get parser errors at runtime.  Note: Errors are supposed to get better in future versions.
    • If you try to move all of the attributes to styles, you may get some parser errors at runtime.  Some of the attributes that are more control specific need parenthesis in their Setter.  For instance, you'll need to refer to "(Grid.ShowGridLines)" instead of "Grid.ShowGridLines" in your Setter.  Most of these attributes in the sample are just in there for debugging and aren't there in the final code sample.
    • You'lll notice the WatermarkedTextbox changes to TextBox in code pics.  This is because of the changes for WPF in Part 8.  Either works.
  • PART 5
    • This is where Data:DataGrid becomes a Listbox.  Don't forget to set the TargetType in the style Setter appropriately or you'll get runtime errors.  If you continue to use the DataGrid, you'll need to add the namespace line from above to the App.xaml file as well.
  • PART 6
    • If you follow the code to the letter, you'll need to add the DiggSample namespace to the top of Page.xaml:
      • xmlns:Digg="clr-namespace:DiggSample;assembly=DiggSample"
    • You'll need to remove the default width and height on the StoryDetailsView.xaml control or else it will get cut off. 
    • There seems to be an error with title field conversion with some content (dashes, maybe?).  I don't expect this to be a fault-tolerant app.  If you get an error clicking through a Digg link, just try another. 

So that's about it.  Like I said, all minor irritants.  I hope this saves you a bit of time.

Comments

Thanks

I had trouble getting Part 6 to work until I tried "basketball" as you recommended.  Now for payback: there is a great SilverLight video on ADO.NET Data Services at: 

http://services.digg.com/stories/topic/spears?count=20&appkey=http%3A%2F%2Fscottgu.com

The title of the video is: 

Basic Silverlight Client for ADO.NET Data Services

By the way, did you know that ADO.NET Data Services is a specialized application of WCF for the Linq to entities framework?   Also, the UK author on his web site has another video showing how to use LINQ to query ADO.NET Data Services. Hot! Hot! Hot!

richardfen@cox.net
Richard Fencel at 5/14/2008 10:09 PM