Custom Loading Screens in Silverlight

About 99% of the time, when I watch a Silverlight application load, I see the standard loading animation.  I’ve seen some really cool Silverlight applications with a highly polished user experience and yet, they don’t spend an extra 10 minutes to make the loading experience decent.  This is very surprising to me because it is so very easy to make your own custom splash screen that blends much better than the standard splash.

Default Loading Experience in Silverlight (Meh…)

CacheVisualization3

It’s not that I don’t like the default loading animation.  I just get tired of seeing it in almost every single Silverlight application out there.

Here is an example loading screen from Silverlight Contrib.

image

This only took a few lines of code to accomplish.

Silverlight Plugin Host:

<script type="text/javascript" src="Splash/SplashScreen.js"></script> 
...
...
<object id="Xaml1" data="data:application/x-silverlight-2," 
type="application/x-silverlight-2" width="100%" height="100%"> ...
<param name="splashscreensource" value="Splash/SplashScreen.xaml"/>
<param name="onSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" />
...
Splash.xaml:
<StackPanel xmlns="http://schemas.microsoft.com/client/2007" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
VerticalAlignment
="Center" Margin="0,100,0,0">
<Image Source="../Splash/slc-watermark.png"
Height
="47" Width="343"
HorizontalAlignment
="Center" VerticalAlignment="Center"
Margin="10" />
<Grid HorizontalAlignment="Center">
<Rectangle x:Name="rectBorder" StrokeThickness="1" Stroke="#FFC8C8C8"
Height
="7" Width="200" HorizontalAlignment="Left"/>
<
Rectangle x:Name="rectBar" Fill="#FFC8C8C8"
Height="7" Width="0" HorizontalAlignment="Left" />
</
Grid>
</StackPanel>
SplashScreen.js
function onSourceDownloadProgressChanged(sender, eventArgs) {
var myHost = document.getElementById("Xaml1");
var rectBar = myHost.content.findName("rectBar");
var rectBorder = myHost.content.findName("rectBorder");
if(eventArgs.progress)
rectBar.Width = eventArgs.progress * rectBorder.Width;
else
rectBar.Width = eventArgs.get_progress() * rectBorder.Width;
}

Ok, now that I’ve shown you how easy it is to create your own splash screen, go fix your apps!  No excuses!!


Feedback

# re: Custom Loading Screens in Silverlight

Gravatar I couldn't agree with you more. Thanks for the tip! 2/19/2009 10:39 PM | Eman

# re: Custom Loading Screens in Silverlight

Gravatar The depressing thing about the default loading control is that everytime we demo our app to a client, the first thing we get is "oooh, i like THAT" while waiting for all our hard work to appear. *sigh*

good post though, thanks - we've been meaning to get around to a custom loader - it's cool to see how easy it is. 2/20/2009 2:44 AM | Nick Harewood

# re: Custom Loading Screens in Silverlight

Gravatar just a quick question, im new to xaml but i cant see from your markup how the border to the loading bar will display ontop of the bar itself? Wont they appear one under another?

I was expecting to see them positioned on the grid abolsutely? What am i missing? 2/20/2009 3:21 AM | Brian

# re: Custom Loading Screens in Silverlight

Gravatar I've had problems using this approach with the ASP.NET Silverlight control. When the onSourceDownloadProgressChanged function is called then there seems to be no way to get the progress from the eventArgs.

That's why the Silverlight 2 collaboration system we've launched:

http://www.colaab.com

Does not have a custom loading screen!

Thanks,

Bob

--
storm ideas
http://www.colaab.com
http://blog.stormideas.com
twitter: movingforwards 2/20/2009 4:13 AM | Bob Thomson

# re: Custom Loading Screens in Silverlight

Gravatar Brian,
Grid controls implicitly stack child controls if you don't specify a row or column on the child control. Since I did not specify a row or column for the child controls, they both default to Row=0, Col=0. If I used a stack panel, they would appear as you described. 2/20/2009 8:17 AM | Page

# re: Custom Loading Screens in Silverlight

Gravatar Bob,

I rarely use the ASP.NET Silverlight control, it's easy enough to create your own UserControl to generate the object tags and you get so much more control of what it's actually doing. 2/22/2009 10:36 AM | Bill Reiss

# re: Custom Loading Screens in Silverlight

Gravatar I totally agree with Bill. You aren't really getting much by using the ASP.NET server-side control. To add to this, when using ASP.NET MVC with Silverlight, I only like to use ASP.NET server-side controls if I have absolutely have to. 2/22/2009 11:28 AM | pbrooks

# re: Custom Loading Screens in Silverlight

Gravatar Nice post thanks. The problem is that I am a little new to Silverlight and I am having some problems using this. Do we place this into the XAML file that has our application controls in it. Is it a separate page? It is not clear from this exactly one has to do to integrate this into their Silverlight apps. Maybe it is clear but I am missing it.
Thanks. 2/24/2009 12:55 PM | Jeff

# re: Custom Loading Screens in Silverlight

Gravatar The Splash.xaml file is separate from your application (XAP). The Silverlight plugin looks for the file specified by splashscreensource just before it starts downloading the XAP package. It then calls out to the function defined by onSourceDownloadProgressChanged. The JavaScript method is responsible for updating the visuals defined in Splash.xaml. I hope this helps! 2/25/2009 8:43 AM | pbrooks

# re: Custom Loading Screens in Silverlight

Gravatar Do you have your example saved as a downloadable project? I am having an issue where the splash screen doesn't actually display and errors our generated. When I edit the xaml file, it says that "type 'Grid' was not found". I am not sure what I am missing. 3/7/2009 5:33 PM | Todd Herman

# re: Custom Loading Screens in Silverlight

Gravatar I hope someone can help me out here as I have few hairs left on my head to pull out. The provided example does not work for me. I downloaded and ran approximately 3 different splash screen examples, none of them worked. I followed the instructions in this article and the instructions in about 4 others, all failed.

I do not receive any errors and I have crammed over 20MB of files into a resource file to bloat the XAP. I have VS 2008 SP1 and the SIlverlight Tools for it.

As a test, I took out the calls to a custom splash screen and even the default splash does not display and there is at least a 5 second wait before starting the application and seeing the test page.

I have nearly exhausted all of my options. Has anyone run into this issue? DO I have something setup incorrectly or is something else causing an issue? 3/8/2009 3:39 PM | Todd Herman

# re: Custom Loading Screens in Silverlight

Gravatar Todd,
Make sure the Silverlight Application can find the XAML file and the appropriate JavaScript file with respect to the hosted page. I would also recommend that you install FireBug to help you determine if the plugin is having difficulties finding the files. If you want to see this in action, you can download the Source of Silverlight Contrib from the following location: http://www.silverlightcontrib.org

I hope this helps! 3/9/2009 8:55 PM | pbrooks

# re: Custom Loading Screens in Silverlight

Gravatar putz....

Could someone explain step by step how to change the default preloader coming in silverlight and replaced by a bar and percentage?

Thanks 4/3/2009 3:51 PM | Jose

Comments have been closed on this topic.