Splash Screen in WPF 3.5 SP1

Besides improving application startup time, .NET Framework 3.5 SP1 also allows developers to add a splash screen to WPF applications. The splash screen is shown using native code, even before WPF application starts to load. In reality this means the splash screen would show immediately when application is started, and fade away a couple of seconds later, when application is fully loaded and main screen displayed.

WPF Splash screen is just and nothing more than a plain bitmap image. Common formats are supported, and if you use a PNG format with a specified alpha channel, transparent areas will be shown accordingly. Just remember to keep it small. Choosing a couple of megabytes large bitmap for your splash screen won’t reduce the loading time. Adding additional information to the image during runtime (title, version number) is also not possible; everything you want to show should be designed in advance and incorporated into a single image.

WPF splash screens can be added to an application in two ways:

Showing splash screen manually

1. Create a new PNG image, which will be your splash screen.

2. Start your Visual Studio 2008 SP1 and create a new WPF project. [make sure .NET 3.5 is specified as the target FX]

3. Choose Project | Add Existing Item… Find and select your splash screen image.

4. Open App.xaml file in design view and look in the properties window ;)

Events in VS2008 WPF designer

Yes, there’s an event panel in WPF designer! And properties/events sorting option buttons!

5. Create a Startup event handler:

   1: private void Application_Startup(object sender, StartupEventArgs e)
   2: {
   3:     SplashScreen screen = new SplashScreen("sp1splash.png");
   4:     screen.Show(true);
   5: }

6. Compile and run.

The SplashScreen constructor takes the name of the resource, which is a splash screen image. The boolean parameter in the Show() method specifies, whether the splash screen should fade out when application is fully loaded. False means you’ll have to hide the splash screen manually using the Close() method.

If you don’t like writing code, this gets even easier:

 

Showing splash screen declaratively

1. Create a new PNG image, which will be your splash screen.

2. Start your Visual Studio 2008 SP1 and create a new WPF project. [make sure .NET 3.5 is specified as the target FX]

3. Choose Project | Add Existing Item… Find and select your splash screen image.

4. Select the newly added image in the solution explorer and show its properties.

5. Change the Build Action to SplashScreen.

6. Compile and run.

The splash screen shows immediately upon the application startup and fades out when the main window is loaded and shown. How’s that for cool new user experience :)

 

Additional note: SplashScreen class works in WPF desktop apps only, XBAPs have their own mechanism for starting up.

Published Monday, August 11, 2008 2:03 PM by Andrej Tozon

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

Monday, August 11, 2008 6:12 PM by Rob Relyea - Xamlified

# 3.5sp1 & VS2008sp1Released

The whole .NET Framework team is very excited to see 3.5sp1 being released today.  2 blog posts

Tuesday, August 12, 2008 12:21 AM by Ngoc

# re: Splash Screen in WPF 3.5 SP1

Hi Andrej, How could I add drop shadow to SplashScreen?
Tuesday, August 12, 2008 12:35 AM by Andrej Tozon

# re: Splash Screen in WPF 3.5 SP1

Hi Ngoc,

the only way is to include a shadow in a bitmap image with your favorite image editing application. Given that transparency is supported with PNG, that should give you plenty of room for creativity regarding drop shadows.

Tuesday, August 12, 2008 3:51 AM by Rob Burke

# re: Splash Screen in WPF 3.5 SP1

The declarative version is wonderful. I feel spoiled by this :)
Wednesday, August 13, 2008 2:41 AM by Andrew Rimmer

# re: Splash Screen in WPF 3.5 SP1

Is it possible to use the new SplashScreen functionality in winforms?
Thursday, August 14, 2008 6:44 AM by Andrej Tozon

# re: Splash Screen in WPF 3.5 SP1

Andrew,

I won't say it's not possible, but it's certainly not designed for it. If nothing else, you would have to resort to some WPF interop to get this working (the SplashScreen class resides in WindowsBase.dll), but this most likely wouldn't give your application startup any performance boost.

Friday, August 15, 2008 2:53 AM by Mark Hatton

# re: Splash Screen in WPF 3.5 SP1

New splash screen is fantastic BUT I'm getting an occasional crash / unhandled exception when the splash screen fades (I'm using the declarative approach so there's no code of mine involved). "Operation completed successfully" was the info but I neglected to grab the error code. Anyone else seen this and got a solution? Cheers.
Friday, August 15, 2008 3:28 PM by Andrej Tozon's blog

# Creating splash screens with Expression Designer

Did you know you can create cool looking splash screens for your WPF application right there with the

Tuesday, August 26, 2008 5:13 AM by Il blog del team MSDN Italia

# Visual Studio 2008 & .NET 3.5 SP1 – Risorse

Per i dev che rientrano oggi dalle vacanze, ecco un aggiornamento importante: il rilascio della SP1 di
Sunday, August 31, 2008 11:55 AM by Logan

# re: Splash Screen in WPF 3.5 SP1

Hi Andrej, thanks for the cool and informative post! My question is does the manual method of displaying the splash screen also allow the screen to be displayed before the .NET framework is loaded? I can't imagine how this could be so, since it allows you to run .NET code in the event handler. So perhaps that benefit is only achieved by the declarative method? Perhaps there is some magic in the SplashScreen class I am unaware of.

Leave a Comment

(required) 
required 
(required)