Wednesday, 27 February 2008

Pre Mix Envy

I am suffering from "Pre Mix Envy", a new condition for developers who want to be in Vegas but can't.

Even if someone donated me a ticket and flight, I wouldn't be able to go as I am working to some very tight project deadlines at the moment.

I wish I could be at Mix looking at the Silverlight 2 stuff as it appears.

However, I am still super excited about Silverlight2 being with us soon and looking forward to lots of Silverlight fun!

Slightly depressed but I have just cheered myself up by buying a Nintendo Wii

Monday, 25 February 2008

Isolated Storage in Silverlight 2

I have updated this slightly (as this was originally written prior to the release of Silverlight 2), but I will do a more indepth article on isolated storage in the future.

100Kb Default Limit

It looks like (via ScottGu's blog), that there will be no increase in the size of isolated storage for Silverlight 2 Beta 1, infact it's now less (silverlight 1.1 was 1Mb). I think it's unlikely that this will increase to drastically in the future (in fact since it has been reduced, it indicates the direction).

My opinion won't be very popular but here we go.
In the past I have been someone who has publicly stated that we need a large default, but i now believe i was wrong. If the default was 100Mb, I am not sure after visiting 10 sites, I would want 1GB of my hard disk taken up.

User Configurable Limit

the good news is that for those folks who need more than 100Kb, this limit is user configurable. So if you need to use more than 100Kb that you will need to ask your users to increase the limit.

Cache Volatile
In Silverlight 1.1 Data stored in Isolated Storage was volatile, so when you clear your browser cache, your isolated storage is also cleared. This has changed in the beta (and it is now stored on your local file system independant of your browser cache). However a user can just go and delete data therefore we need to ensure data is synchronised with the backend server (which means that you need to keep bandwidth in mind).

As a user I am not sure I would be too happy with losing my vital data because it wasn't saved back to the server or with using an internet application that i couldn't use throughout the world (due to my data sitting on my local file system), hence why synchronization is important.

So what should we be storing in the isolated storage?
I believe the point of the isolated storage area is to enhance the UI experience not detract from it, so I genuninely believe that I was wrong, and that Microsoft are right and low limits are sensible (with the flexibility of allowing the user to increase it).

There is no point storing media files in Isolated Storage as the browser already has a perfectly adequate caching mechanism. There is also no point keep vital documents (that are not saved back to the server) for the reasons above.

I believe isolated storage is really about 2 things:

  • Accessing / storing common data to reduce frequency of server calls

  • Temporary storage of data which is synchronised with the back end server.

Good uses of Isolated Storage

To give a flavour of what Isolated Storage should be used for I have given some examples below (this list is by no means exhaustive)

  • Displaying user details in the site e.g. "Hello Bob, Welcome Back Bob"

  • Storage of theme / skin preferences (so when you return to a site, you can see the site with your preferred skin without waiting for a response from the server first).

  • Temporary storage area for document drafts, prior to synchronisation with the server (very useful if internet coverage is flaky)

Bad uses of Isolated Storage

  • The only storage place of every vital document i have ever written

  • Attempting to store the entire contents of wikipedia

The point is if you wish to be a naughty programmer and waste your users hard disk space, you are going to have to ask them very nicely. This is not to say you can't use Isolated Storage in genuine (and innovative ways), you just need to have your users give you permission.

What is more likely to happen (with low default limit) is that there is a better chance that you will enhance the UI experience (and be respectful of hard disk space, and bandwidth), and not degrade it.

If Microsoft can fit Silverlight 1.0 in a 1MB download, and Microsoft can fit Silverlight 2, in a 4MB download, do we really need a 100MB default isolated storage limit.

Silverlight 2 and the Flash Cross Domain Policy Files

In Silverlight 1.1 alpha (today), you cannot make cross domain network calls from within Silverlight. So for example if you deployed your Silverlight application to then you would not be able to make a network call (web service request, http request etc.) to, as security dictates that only calls to are allowed.

In Silverlight 2 this restriction has been relaxed, so that you will also be able to make call to a server which contains either via a Silverlight XML Policy file (I have no details on this), or to a server which contains a flash cross domain policy file (this information comes from Scott Guthries Silverlight DIGG Silverlight client article

Since Silverlight 2 supports the flash crossdomain policy file, this means that any site that currently gives flash access also will allow silverlight access. (DIGG is the example given in ScottGu's blog).

So in this article i will talk a little about this file (as this will work in Silverlight 2 when it is released).

In order to implement the Flash Cross Domain policy you must have a file on your server named crossdomain.xml that is accessible to the outside world. For example you can view the DIGG cross domain policy file here. (tip click on view source).

The following xml will allow Silverlight or Flash hosted on any website to make requests to your service.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
<allow-access-from domain="*" />

If you wish to restrict access to your service to a specific website (e.g., the example is changed to the following

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
<allow-access-from domain="*" />

This hopefully will help you decide which sites you wish to expose access to your own webservices to. It should also allow you to beaver around the internet and find sites (such as DIGG) which has a cross domain policy file that you can connect to already.

Friday, 22 February 2008

First look at Silverlight 2.0 on ScottGu's blog

The main man of the web has done it again!

Get along to his blog for indepth details of the upcoming Silverlight 2.0 beta, including an 8 part tutorial of building a silverlight digg client.

Superb stuff, thanks Scott

Wednesday, 20 February 2008

Silverlight Progress in an AJAXed GridView

This is a quick article on combining Silverlight and AJAX together to make richer user experiences for your existing Web Applications.

There are three parts to this sample:

  • The first part is building a standard gridview that binds to an xml file, and making it run under ajax.

  • The second part is about creating a simple silverlight progress indicator.

  • The third part is about combining the 2 samples together to make a datagrid which uses Silverlight as its progress indicator, rather than HTML.

Part One - Building a simple databound ajax gridview

1) Create a new website in ASP.NET
2) Create an Xml File (called mydata.xml) and drop it in the App_Data folder. My Xml is below:

<?xml version="1.0" encoding="utf-8" ?>
<Item Name="Item1"/>
<Item Name="Item2"/>
<Item Name="Item3"/>
<Item Name="Item4"/>
<Item Name="Item5"/>
<Item Name="Item6"/>
<Item Name="Item7"/>
<Item Name="Item8"/>
<Item Name="Item9"/>
<Item Name="Item10"/>
<Item Name="Item11"/>
<Item Name="Item12"/>
<Item Name="Item13"/>
<Item Name="Item14"/>
<Item Name="Item15"/>

3) Drop an XmlDataSource onto the page, and set the datafile

<asp:xmldatasource runat="server" id="itemsDataSource" datafile="~/App_Data/MyData.xml"></asp:xmldatasource>

4) Drop a gridview onto the page and set the datasource

<asp:GridView ID="GridView1" runat="server" DataSourceID="itemsDataSource" AllowPaging="True" PageSize="5" OnDataBinding="GridView1_DataBinding"></asp:GridView>

5) Add some code to send the page to sleep for a few seconds on databind

protected void GridView1_DataBinding(object sender, EventArgs e)
if (IsPostBack)

6) You should now be able to run the sample on your site
7) If all is okay, we can now ajaxify it, so drop a scriptmanager onto the page, drop an UpdatePanel and UpdateProgress on the page
8) Stick the gridview within the update panel, and put a message like Hello World in the Update progress. You should now have some like the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:GridView ID="GridView1" runat="server" DataSourceID="itemsDataSource" AllowPaging="True"
PageSize="5" OnDataBinding="GridView1_DataBinding">
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
Hello World
<asp:xmldatasource runat="server" id="itemsDataSource" datafile="~/App_Data/MyData.xml"></asp:xmldatasource>

Part 2 - Creating the Silverlight Page (1.1, but 1.0 will also work)

1) Add a silverlight project to your solution
2) Modify the Xaml to the following (this will create a rotating label with the text "Please Wait"

<Canvas x:Name="parentCanvas"
<Storyboard Storyboard.TargetName="myRotate"
<DoubleAnimation From="0" To="360" Duration="0:0:05"/>
<TextBlock x:Name="myTextBlock" Text="Please Wait" Canvas.Left="25" Canvas.Top="50">
<RotateTransform x:Name="myRotate" Angle="0" CenterX="30" CenterY="10"/>

You should now be able to run your project and all will be fine and dandy.

Part 3 - Integrating the two together

1) On your website, click "Add Silverlight Link", and click on your Silverlight project
2) Copy the silverlight.js file to your website
3) Copy TestPage.html.js to your website and rename it to Default.aspx.js
4) Comment out the section of the Default.aspx.js which does the document.body.onload, your Default.aspx.js file should now look like this

// JScript source code

//contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight()
source: "Page.xaml",
parentElement: document.getElementById("SilverlightControlHost"),
id: "SilverlightControl",
properties: {
width: "100%",
height: "100%",
version: "1.1",
enableHtmlAccess: "true"
events: {}

// // Give the keyboard focus to the Silverlight control by default
// document.body.onload = function() {
// var silverlightControl = document.getElementById('SilverlightControl');
// if (silverlightControl)
// silverlightControl.focus();
// }


5) Modify the head tag of your default.aspx to include the javascript files

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript" src="Default.aspx.js"></script>
<style type="text/css">
width: 150px;
height: 150px;

6) Modify the Update Progress to include your silverlight control

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<div id="SilverlightControlHost" class="silverlightHost">

<script type="text/javascript">


7) You should now be able to run your website and have a Silverlight progress indicator.

You will obviously be able to do even cooler things like proper animations, media etc

Have fun, the full source is available on my skydrive

MacBook Air suffers from internationalization issues

This isn't strictly Silverlight but hey this is fun!
One of my buddies received his new MacBook Air today., nfortunately Steve Job's claims don't stand up to the international market. As you can see the MacBook air doesn't fit in an A4 envelope.
Ah well, now I wonder if you can install Vista on it.
However I think I will convince Tom to bring it in more often, so I can do some Silverlight testing with it.

Sunday, 17 February 2008

Code Reuse (in Silverlight Today)

Following on from my previous posting where I ask for some support in Visual Studio for Code Reuse with Silverlight projects. Daniel Moth (one of Microsoft UK's evangelists) kindly posted a current workaround suggestion in the comments on a workaround that you can use today to reuse code between Silverlight and Non Silverlight projects.

You can read in more detail about Daniel's workaround in his MSDN article that he did last year (which is Compact Framework related).

They key thing that Daniel is suggesting, is that to reuse common code in both Silverlight and Non Silverlight projects, you should do the following.

1) Create two versions of the assembly (one silverlight and one regular .NET Framework)
2) Create the class in the regular class library as normal
3) In the silverlight version of the project -> Select Add Existing Item -> and within the Open File Dialog, select the "Add as Link" option

Daniel also suggests that you can use the following techinques to handle the differences between framework implementations

  • Conditional Compilation

  • Extension Methods

  • Partial Types

This is some really great workarounds from Daniel on how to getting around some of these issues today and promotes a great way for you to be able to reuse code already (rather than cutting and pasting).

I still have one major concern, which is that there is still quite alot of overhead to reusing code. You still have to maintain two versions of each assembly (3 if you wish to reuse between silverlight, compact framework, and full .NET Framework), you as a developer need to constantly check your code compiles against the 2 platforms, you need to think about your compiler directives etc.

Although this is a great workaround (and I recommend you use these techniques), I still think that Visual Studio should provide us this support, using a technique such as the virtual assembly reference (that i suggested in my previous post).

Thanks again to Daniel for this workaround and I believe he will be writing up a Silverlight version of his article (which I look forward to), however there should be enough information here to get you going with code reuse between Silverlight and Non Silverlight projects today.

Saturday, 16 February 2008

Silverlight and Code Reuse with non Silverlight applications

One of the problems we face with Silverlight is that Silverlight Projects can only reference Silverlight Class libraries, and other types of projects (such as WPF) cannot reference those Silverlight class libraries.

For example if I have a common static class has one static method that returns hello world.

namespace MyCrossCode
public static class Common
/// <summary>
/// Returns Hello World
/// </summary>
/// <returns></returns>
public static string HelloWorld()
return "Hello World";

Then its logical that i would want to be able to share that class in 2 different versions of my application without code duplication.

With the current referencing model it leaves us in an awkward situation as we want to be able to resuse common code if possible in both applications without having to maintain two versions of the code.

I suggest one solution for Microsoft would be to provide us the ability in Visual Studio to be able to add code compliant with both the targetted version of the .NET Framework and with Silverlight. Compilation would produce us two versions of the assembly and the Silverlight version is automatically included in our Silverlight apps and the non Silverlight version for our Windows versions of our applications.

One way this could be achieved is the using a concept of Virtual Assembly reference, so rather than referencing the assembly directly, we reference a virtual assembly. So if its a Silverlight Application it will use the Silverlight version of the assembly, and if its non Silverlight it will use the non Silverlight version. The key thing about compliant projects is that non cross compatible code will fail to compile.

Anyways, I hope Microsoft looks at implementing this solution (or another solution) to this problem (especially in the Silverlight 2.0 timeframe).

Monday, 11 February 2008

Does the BBC plan to use Silverlight for the IPlayer?

The BBC has said that they will have a download version of the IPlayer for Mac Users by the end of 2008.

My question is that this seems to fit in nicely with Silverlight 2.0 timelines, and since the current IPlayer uses Windows DRM are they planning to hit the Mac gap with Silverlight 2.0.

With an increased isolated storage limit for Silverlight 2.0, DRM support for Silverlight 2.0 and an end of 2008 timeline for the BBC, it seems like the BBC might have made their choice.

This is just an educated guess but it would be absolutely superb if the BBC did choose Silverlight as their technology choice.

Let time tell

VS2008 Web Development Hotifx

This is a very welcome hotfix from Microsoft, fixing some of the common web issues with VS2008 that I'm sure a lot of us have been experiencing.

You can download the hotfix from here.

Details of the hotfix via ScottGu's blog

Sunday, 10 February 2008

Happy Birthday

It's my birthday today, Happy Birthday to me.

I've had lots of nice presents but the best present of all is my brother is coming out of hospital this weekend (he had a stroke a few weeks ago, and we now know he has a brain disease of some sort, but he should live a full and healthy life as long as he keeps his blood pressure low). This is the main reason, I haven't been blogging for a while.

Anyways, I'm off to wind my dogs up with my new radio controlled helicopter, and full blogging service should resume soon.

Sunday, 3 February 2008

Giants Win Superbowl

I've been a Giants fan for a very long time, and I am one very happy boy this evening.

Especially since i had the pleasure of watching the superbowl winning team live at Wembley earlier this year