Welcome to EMC Consulting Blogs Sign in | Join | Help

Howard van Rooijen's EMC Consulting Blog (2004 - 2010)

This blog has now moved to http://howard.vanrooijen.co.uk/blog - please update your subscriptions if you wish to receive new content.

A week with Silverlight 1.1

Richard Griffin, Steven Evans and I spent a week working on a Silverlight demo that Paul Dawson used as part of his ReMix presentation "WPF & Silverlight: A Loaded gun?" although I can't publish the demo yet, I thought it might be useful to go over some of the things we learnt putting it together.

All three of us have WPF experience; we've read the de facto books and we all worked on Daily Mail eReader project; so a lot of that knowledge was transferable to development in Silverlight. None of us had played with Silverlight when it was in its WPF/e incarnation (but fellow conchango-ite John Rayner did) and although Richard and I have plenty of experience getting our hands dirty with JavaScript, after Mix07, Silverlight 1.1 Alpha was the version we really wanted to get our teeth into. So here are a few of our learnings:

Ensure you have correct bits installed

I know this sounds obvious – but if you're an alpha geek who installs all the latest CTPs, it's easy to get out of synch and then spend hours wondering why the project doesn't compile correctly. Follow the official instructions. If you don't want to contaminate your dev machine – create a VPC image and then tune it.

Also make sure you have the tool you need for testing / debugging / troubleshooting when things go wrong:

Update Blend 2.0 May CTP to work with Orcas Beta 1

Blend 2.0 May CTP doesn't integrate with Orcas Beta 1 projects out of the box – you need to create a Blend.exe.config file in the applications directory which updates Blend's MSBuild version to Orcas' version. The full steps are outlined in the Blend 2 May CTP Readme file.

Use Blend 2.0 May CTP for layout and adding controls

The build of Cider (the WPF design surface) that ships with Orcas Beta 1 does not support the Silverlight XAML schema yet (thus inside Orcas you always get the "code view" of .XAML files) so unless you want to do layout, animation and custom control addition by hand you'll need to do all of that in Blend.

One note of caution – Blend sometimes seems to create invalid xmlns directives when referencing external assemblies; the project will compile inside Blend, but not Orcas. Ctrl-Z is your friend in this scenario.

"Add Silverlight Link" NOT "Add Reference"

If you have a multi-project solution, one of the peccadilloes of Silverlight emerges – you can't link projects together using the standard "Add Reference" option – you have to use the new "Add Silverlight Link" option instead – otherwise project content (i.e. XAML files, folders and .dlls) are not updated correctly.

Define your Solution and Project structure

We knew from the start that we were going to have multiple projects within our solution. We wanted to separate out the website, Silverlight application and Silverlight controls. So we followed the Conchango reference build structure and then added three projects under the "Solutions" folder:

  • ProjectName.App – this contains the Silverlight Application
  • ProjectName.Controls – this contains all the reusable controls such as Buttons, Sliders etc
  • ProjectName.Web – this contains the website which hosts the Silverlight app.

ProjectName
+---Main
¦ +---Build
¦ +---Solutions
¦ +---Common
¦ +---ReferencedAssemblies
¦ +---ProjectName.App
¦ ¦ +---Assets
¦ ¦ ¦ +---PageName
¦ ¦ ¦ +---Music
¦ ¦ ¦ +---Video
¦ ¦ +---ClientBin
¦ ¦ +---Properties
¦ +---ProjectName.Controls
¦ ¦ +---Assets
¦ ¦ +---ClientBin
¦ ¦ +---Common
¦ ¦ +---Properties
¦ +---ProjectName.Web
¦ +---App_Code
¦ +---App_Data
¦ +---Scripts
¦ +---Styles
+---TeamBuildTypes
+---DEV

Project.App was linked into ProjectName.Web throught the use of the "Add Silverlight Link" mentioned in the previous tip. Once the Solution is compiled this caused all the contents (Folders, XAML files and .dlls) to be copied into the ProjectName.Web project. So ensure your ProjectName.Web project is clean before you add it to Source Control – otherwise you'll hit problems when you build your project in the future.

To keep ProjectName.Web as clean of referenced files as possible, we settled on the convention of keeping all images, music and video in a folder called Assets. Because the design of our app is quite graphically intensive we decided to create a folder per XAML Page to contain its graphics.

Missing basic controls? Turn to the Community...

Silverlight 1.1 is an Alpha release after all – so much of the RTM functionality is still missing, including many of the intrinsic controls you'd use on a day to day basis (such as Button, TextBox etc). One solution is to use and modify the samples supplied as part of the Silverlight 1.1 Alpha SDK or you could try experimenting with the more extensive Layout System and Controls recently released by Dave Relyea.

Gather as many samples as you can

The best way to learn it to check out what everybody else is up to. For the first few weeks after Mix07 samples were a little thin on the ground (oh look! Another rotating rectangle that's clickable!). I found the following links quite useful:

When copying sample code ensure your Build Actions are correct

I first fell foul of this issue when I imported the Silverlight 1.1 Alpha SDK controls sample into our ".Controls" project. I selectively imported the files I wanted to use and could not, for the life of me, workout why the Button control would not load and caused a runtime error.

Because Silverlight 1.1 does not support the WPF style of XAML file / nested partial class code-behind, the workaround is having a XAML file as an embedded resource with the same name as the class file. In the constructor of the class reflection is used to extract the XAML file and instantiate it.

If you import the files into a project you will lose the Build Action settings which will specify that the XAML files are "Embedded Resource" rather than "SilverlightPage" thus when the class is instantiated the XAML file cannot be retrieved from the Assembly Manifest and the exception will be thrown.

Add ASP.NET Futures controls to the toolbox

A new drop of the ASP.NET Futures project was released to coincide with the release of Silverlight 1.1 Alpha. This project adds two ASP.NET server controls; a Media Control which simplifies the hosting of audio and video and a XAML Control which eases the pain of hosting XAML files.

To add the controls to the Toolbox you need to right click, select "Choose Options", select the ".NET Framework Components" tab, sort the list by Namespace and browse to Microsoft.Web.Preview.UI.Controls and select the "Xaml" and "Media" options. You should now be able to drag and drop the controls onto the page from the toolbar.

ASP.NET Futures XAML Control has a fundamental bug

The current implementation of the ASP.NET Futures XAML control causes the same "Click to activate" issue that has affected the Flash community for the past couple of years since the Microsoft / Eolas case. The simplest workaround is not to use the XAML control, as the default method for instantiating the Silverlight plug-in does not cause this behaviour. This issue should be fixed in the next release.

Enable Silverlight Debugging in Web Projects

If you are trying to debug your Silverlight application from within a Web Project and for some strange reason none of your breakpoints get hit – ensure that you've selected Silverlight Debugger option in the "Web Project Property Pages > Start Options > Debuggers" section.

Orcas Web Project Property Pages

Isolated Storage Quota

Silverlight 1.1 Alpha allows applications to persist up to 1mb of data locally (similar to Flash's Shared Objects), which allows for much more flexibility for storing data than the 4kb limit for http cookies (think local data cache). There are several good examples of how to implement Isolated Storage in both C# and Managed JavaScript.

Published Monday, June 04, 2007 10:11 PM by howard.vanrooijen

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

steven evans said:

Further to Howard's post regarding our trials and tribulations whilst developing a Silverlight Alpha,

June 10, 2007 5:09 PM
 

Scott said:

You mentioned that "Blend sometimes seems to create invalid xmlns directives when referencing external assemblies." How can I fix this type of error? What is the correct syntax to refrence and external assembly?
June 13, 2007 2:35 PM
 

howard.vanrooijen said:

Hi Scott,

I generally noticed that Blend has done something wrong because I had the solution open in both Blend 2.0 and Orcas and would swap between the two. The symptom I'd see was that Blend would compile the solution, whereas Orcas would throw an

build error. Then it was just a case of using ctrl-z to undo the action in Blend.

I don't have any specific errors to hand - but what I generally noticed was that the xmlns directives were not in the correct format - I think they missed out the full namespace declaration or didn't reference the ClientBin folder. This seemed to be an intermittent bug. Redoing the action generally resulted in the desired result.

June 13, 2007 4:05 PM
 

howard.vanrooijen said:

Hi Scott,

forgot to mention that Steve Evans has listed some of the Blend problems and workarounds on his blog:

http://blogs.conchango.com/stevenevans/archive/2007/06/06/Silverlight-Adventures-with-Blend.aspx

June 13, 2007 4:07 PM
 

Eric Nelson - Development for .NET Framework 3.0 for ISVs said:

The choice of technology for delivering UX is getting wider. Three years back it would have been (in

September 5, 2007 9:07 PM
 

It's the what I looking for with combine of ASP + SL but ... said:

I have my own small problem with the debug issue in a combine project like this article talk about : Here is the link : http://silverlight.net/forums/t/5278.aspx Please if someone could figure it out .. ( It's very simple just why 1 debug don't hit ) Please send me a message on that thread . Thank Guy.
September 30, 2007 11:50 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

This blog has now moved - please visit http://howard.vanrooijen.co.uk/blog for new content!
Add to Live.com
Powered by Community Server (Personal Edition), by Telligent Systems