Splash Screen in WPF 3.5 SP1

by Andrej Tozon 11. August 2008 14:03

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.

Tags:

Software | User Experience | WPF

Comments

8/12/2008 3:51:32 AM #

Rob Burke

The declarative version is wonderful. I feel spoiled by this Smile

Rob Burke | Reply

8/13/2008 2:41:10 AM #

Andrew Rimmer

Is it possible to use the new SplashScreen functionality in winforms?

Andrew Rimmer | Reply

8/15/2008 2:53:01 AM #

Mark Hatton

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.

Mark Hatton | Reply

8/31/2008 11:55:03 AM #

Logan

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.

Logan | Reply

8/28/2009 11:07:40 AM #

Cody

The manual method can load the splash screen before all of WPF loads, but not if you do it as described in this post.  You have to override the main method for your project (several ways to do this in WPF) then create and show the splash screen before creating the App object.

Cody United States | Reply

9/14/2009 3:25:06 PM #

G. McDorman

Known bug with no fix. Search for "wpf splash screen crash" and look at the first result.

G. McDorman Canada | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading





Andrej Tozon
Andrej Tozon's on Twitter View Andrej Tozon's profile on LinkedIn Subscribe to me on FriendFeed Andrej Tozon's Facebook profile

MVP - Client Application Developer

Microsoft Certified Solution Developer

MSN Alerts

Get help from Andrej Tozon!

 

Currently reading


Microsoft Silverlight 4 Data and Services Cookbook

Stay tuned for the review... In the mean time, you can read an excerpt from the book.

RecentComments

Comment RSS