Wednesday, August 20, 2008

Splashing WPF

Since WPF application's startup were slow, specially when cold starting, I always ended up thinking "How can I add a splash screen to my WPF application?", but if you create a splash screen in XAML there are lots of things that should be loaded before your splash screen is shown....see the irony in that?

I've had my own way of doing it, but what some people did was to create a Win32 library to display the splash screen (a simple picture), so the splash screen is shown as soon as the first bits of the applications is run, then when the WPF related assemblies are loaded, maybe you could display a more elaborate splash screen, even in Xaml. That's the approach taken in applications like Expression Blend and Expression Design.

Now, with the release of SP1 for VS.NET 2008, there is a new functionality which you could use to display Splash screens when your WPF application is loading. It may not be as fast as Win32 library solution, and it will not improve application's cold start time, but it is very easy to do.Adding a splash screen may not be so obvious, because there is no template in VS.NET 2008 new dialog! So, either you can download the splash template here, or use the code to display a picture as a splash screen. To do the latter, you can add a picture to your project and set the Build Action to Resource and then use the following snippet to make it work :

SplashScreen splash = new SplashScreen("SplashScreen.png");
//Do application initialization here...

Happy splashing!

Updated : Here's the link to download the template from CodePlex.
Submit this story to DotNetKicks Shout it

1 comment:

Omid said...

Nice! You've probably forgot to mention the link to the template.