Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF application window appears on top of SplashScreen

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?

like image 378
sourcenouveau Avatar asked Oct 27 '09 16:10

sourcenouveau


People also ask

How do I keep windows on top of WPF?

Basically, to keep it on top you just set the lose focus event to make it go back to top.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

How do I make a splash screen in WPF?

In the Properties window, click the drop-down arrow for the Build Action property. Select SplashScreen from the drop-down list. Press F5 to build and run the application. The splash screen image appears in the center of the screen, and then fades when the main application window appears.


2 Answers

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.

like image 111
Helge Klein Avatar answered Sep 23 '22 00:09

Helge Klein


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);

like image 23
Daniel Avatar answered Sep 25 '22 00:09

Daniel