Thursday, March 25, 2010

Silverlight 4 Hands On Lab

Silverlight Data and Controls Series

Hands On Lab for Silverlight 4

After the Mix 2010 Conference there has been a lot more excitement for Silverlight 4 and RIA Services. If you want to start to learn Silverlight 4 and RIA Services this is what I would recommend. First go the Silverlight website and review some of the learning materials there - there is a ton of good stuff there (

However most of us require a more hands to actually learn something. I recently found that the Swiss MSDN Team published a very detailed Silverlight 4 Hands On lab here -

This lab is absolutely great in that is over 100 pages of step by step labs that taught me the following:

  • How to create a Silverlight and RIA Service Project.
  • Created a simple Entity Model and wired up a grid.
  • Incorporated both Server and Client side filtering of data in the grid with RIA Services and LINQ.
  • Added a Busy Indicator and DataPager controls to the grid.
  • Added custom formatting and sorting to grid columns.
  • Added an AutoComplete control to filter the grid.
  • Added persistence to the grid to perform CRUD operations. Plus added concurrency checking to the grid.
  • Created a data form for master and detail data to support for CRUD operations
  • Implemented server side validation attributes to domain classes and created custom validation classes.
  • Added custom lookups into the data form.
  • Created a custom Data Transfer Object (DTO).
  • Created custom domain methods.

There were several other labs which I did not complete on:

  • New printing capabilities of Silverlight 4.
  • Add right click menu items
  • Using the clip board.
  • Using COM Interop to send data to Excel.

Creating Lab Environment

I really found the labs a great way to learn Silverlight 4.

This lab was built for Silverlight 4 with Visual Studio Beta 2. As you know with the announcements at the Mix Conference, you can now use Silverlight 4 with Visual Studio 2010 RC. Plus a new RIA Service RC was also released. To get started doing this lab do the following:

Modifications to Lab

Since this lab was published there have been some changes and not all things worked. There were a few small things that you will have to differently to complete the lab. This is because RIA Services RC release changed up several things.

Page 21 – Use System.ServiceModel.DomainServices.Client instead of System.Windows.Ria. Reference -

Page 41 – Use the following for Code Snippet 7 instead of what is provided:


<riaControls:Parameter ParameterName="city" Value="{Binding ElementName=shipCityBox, Path=Text}" />



Page 45 - Data Conflict Detection – This section was seems to be out of place, skip it and complete later.

Page 63 - Snippet 12 – Need to modify the code slightly.

return new ValidationResult("Maximum freight cost for UK exceeded.", new string[] { "Freight" });

1 comment:

Andrew Moore said...

Another correction for you:

Page 73, snippet 22, instead of this:


use this:


The former results in an InvalidOperationException (An object with a null EntityKey value cannot be attached to an object context).

Frankly, the best part about labs like this are when they have little issues with them that need to be diagnosed. I know I always get a little more out of them when I need to think about why something isn't working properly rather than just copying and pasting code to see the results.