Thursday, August 27, 2009

Serving Silverlight 3 apps from IIS6

If you want to serve Silverlight 3 apps from an IIS6 server running on Windows Server 2003 you need to add the following three mime types (I added them at the server level). If you don’t make these changes the web page will show a blank Silverlight window. You can right click to get the Silverlight menu but your app does not run.

.xap     application/x-silverlight-app
.xaml    application/xaml+xml
.xbap    application/x-ms-xbap

I discovered that IIS needs to be restarted before the settings take effect. To restart IIS run IISRESET from a command prompt.

Saturday, August 22, 2009

WPF auto fading error message

Here is a small control template to display an error message. The message will fade away after a couple of seconds. You set the message like this:-

Label1.Content = DateTime.Now.ToString();

Here is the xaml:-

<Window x:Class="TRM_Uploader.Window2"
Title="Window2" Height="300" Width="300">
<ControlTemplate x:Key="MyErrorMessage"
TargetType="{x:Type Label}">
<StackPanel Orientation="Horizontal"
<Border CornerRadius="4"
<Label Foreground="White"
<!-- This TextBlock accepts the content from the parent 'label'. It is not actually displayed, just used to bind data-->
<TextBlock Name="Part3"
Text="{TemplateBinding Content}"
<!-- This TextBlock binds to the one above and triggers an animation when it gets updated. -->
<!-- Its required because TemplateBinding does not allow NotifyOnTargetUpdate -->
<TextBlock Margin="2"
Text="{Binding ElementName=Part3, Path=Text,NotifyOnTargetUpdated=True}"
<!-- When Text property of Part2 is blank hide entire control-->
<Trigger SourceName="Part3"
<Setter TargetName="ErrorMessage"
<!-- This trigger is called when Part2 updates which in turn is updated by Part3's databind.
It uses animation to make the label fade away after a few seconds. -->
<EventTrigger SourceName="Part2"
<Storyboard TargetName="ErrorMessage">
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1.0" />
<DoubleAnimation Storyboard.TargetProperty="Opacity"
BeginTime="0:0:1" />
<StackPanel Orientation="Vertical">
<Label Template="{StaticResource MyErrorMessage}"
<Button Click="button1_Click">click to test</Button>

And the c#


public partial class Window2 : Window
public Window2 ()

private void button1_Click (object sender, RoutedEventArgs e)
Label1.Content = DateTime.Now.ToString();

Thursday, August 20, 2009

How to make a bootable USB memory stick in Windows 7

I spent ages on this last night without any success, tonight it took me about 60 seconds. Here is the trick.

First you need to download Windows Enabler from This allows any disabled controls to be re-enabled. Install the program and click on its system tray icon to enable it. The Icon should show ‘on’ to show it’s working :

With Windows Enabler running you can go into Windows Explorer and format your memory stick (obviously this will erase everything on the stick). Normally the “create an MS-DOS startup disk” is disabled for everything except floppy disks but with Windows Enabler running you can click the disabled checkbox to use the option with any drive.

I think the file system needs to be set to “FAT”. Once formatted your stick will be a bootable MS-DOS 4.9.3000 boot disk. Easy!

IE image visibility bug

I found two very strange bugs in IE 8 yesterday (probably in other IE versions as well). I have an image and some text in a SPAN that is made visible with some JavaScript. Here is the HTML :

<img id="ctl00_ContentPlaceHolder1_Image3" src="Graphics/waiting.gif" align="middle" style="border-width:0px;visibility:hidden" />

<span id="ctl00_ContentPlaceHolder1_Label4" style="visibility:hidden">Please wait. Adding results to database.</span>

The Javascript attempts to change the visibility like this :'visible';'visible';

for SPAN tags this works. for IMG tags it has absolutely no effect!

The solution is a horrible hack :-

<script type="text/javascript">

function UploadComplete()



window.setTimeout(TurnAnimatedGifBackOn, 500);


function TurnAnimatedGifBackOn ()


var tmp = document.all.ctl00_ContentPlaceHolder1_Image3;

if(typeof (tmp) == 'object')

{ = 'visible'; tmp.src='waiting.gif';




To fix the problem the IMG tag has to have it’s display property toggled from ‘none’ and back to ‘block’.

The second bug is that animated gifs stop animating when a page post back occurs. To fix this problem I’ve used a timer to alter the image 500ms after the page post back. To get the animation working the src tag must be reloaded with the image url.

Other browsers do not seem to have this problem.

Enable Hardware Virtualization on Sony VGN-AR71ZU

It is really annoying to discover that Sony disable hardware virtualization and do not provide a bios setting to allow it to be re-enabled. This prevents you from being able to use Windows Virtual PC/MP Mode in Windows 7. I finally managed to hack the bios and now have full hardware virtualization!

Hacking the bios is actually trivial provided you know the right register to change. Chris Hay has a blog post which describes the change for a VGN-AR71ZU (bios = Phoenix R2090J8). (

The trouble I had was creating a bootable USB memory stick. I spent hours messing around last night with absolutely no success. In the end I gave up on the USB stick and found an old USB floppy drive. I downloaded the ms-dos 6.22 disk images from MSDN and made myself a set of three setup disks. I then booted off the floppy, exited ms-dos setup with F3 and ran SYMCMOS as described in Chris’s blog post. The process was not helped by the fact that the USB floppy would not work on Vista or Windows 7 so I had to create the ms-dos setup disks on an old XP machine.