5

I followed the simple steps outlined at How to: Add a Splash Screen to a WPF Application to add a splash screen to my WPF application. When I start the application, the splash image is shown, then the main window pops up, and the splash image fades away.

My problem is that when the main window pops up, it appears on top of the splash image. Then when the splash image begins to fade out, the splash image pops up to the top again. The end result is that the splash image disappears for a split second as the main window appears.

How can I force the main window to appear under the splash image, so that the splash image does not disappear?

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

3 Answers3

7

In .NET 4.0 an overload has been added to the Show method that allows to set the window style WS_EX_TOPMOST on the splash screen window. Show the splash screen in code like this:

SplashScreen splash = new SplashScreen("SplashScreen.png");
splash.Show(autoClose: true, topMost: true);

I call that from the method

protected override void OnStartup(StartupEventArgs e)

in App.xaml.cs.

"SplashScreen.png" is of course the identifier for your splash image embedded in the application's resources.

Helge Klein
  • 8,829
  • 8
  • 51
  • 71
2

This isn't default behaviour you must have some code thats manually focusing the main window?

It may be easier just to turn off the fade manually with a bit of code like this:

_splash = new SplashScreen("LoadingScreen.png");

_splash.Show(false);

_splash.Close(TimeSpan.Zero);

Daniel
  • 2,744
  • 1
  • 31
  • 41
  • I will look to see if there is some code which is doing the focus; it might be from a third-party component. Since I added the splash screen using a resource's Build Action, how would I go about accessing it like you did...? – sourcenouveau Oct 28 '09 at 15:55
  • In your app.cs file declare a global field "protected SplashScreen _splash;". In the constructor have the first two lines of code from above. In your OnStartup event at the end of the method after all the startup logic is completed insert the last line of code above. That should be it. – Daniel Oct 29 '09 at 00:29
0

Not sure if this will help, but if you set the owner of the Splash screen to the current form, then this should maybe do the trick?

_splash.Owner = this;

Otherwise you can look here:

Splash Screen Example

This might help too.

Community
  • 1
  • 1
Richard
  • 3,207
  • 5
  • 30
  • 35