WPF-Window Topmost for own application only?
Asked Answered
C

3

11

The Splashscreen/Loading-Window in my WPF application is set to Topmost="True". Now this windows in on top of all other windows even when you switch to another application (because loading will take some time). I don't want this kind of behavior.

If I set Topmost="False" the window in not topmost at all. But If you switch back to my application after working with with another application my customers sometimes don't realize the Loading-Windows is still working. The application appears to be unresponsive because the Loading-Window in the background is still the active window and it is modal.

I want to have the Loading-Window topmost but only if my application is in foreground. If you switch to another program the window should disappear and reappear topmost when you switch back.

Clerk answered 17/3, 2010 at 14:43 Comment(2)
Just out of curiosity why are you loading other windows altogether while your splash screen is shown? Generally when an application uses a Splash screen, that's the only visible window for that app at that time....Orsino
Because loading takes so long my boss wants some data already be visible in the main window. You can't interact with the data but at least you can look at it.Clerk
A
11

You can try to use the Owner property of the window, with that the splash screen will always overlap the other windows.

Arrio answered 17/3, 2010 at 15:50 Comment(1)
In my application, the MainWindow takes time to create, so it's not yet created while the splash screen is shown. So I can't set the splash screen window's owner to the main window yet.Alonso
C
2

I think maybe a change in the loading pattern of your MainWindow might help. If you can put to time consuming part of loading the window on a background thread then you can take this path:

  1. Show MainWindow empty or bare bones (empty fields/grid etc)
  2. Launch async load method to get data and populate main window
  3. Create splash screen, set owner to self and show
  4. make sure to close splash screen when load is complete.

that should keep the splash on top while load is being processed.

Clerissa answered 10/2, 2011 at 13:50 Comment(0)
E
1

To clarify I will reanswer this question:

Martin Moser's answer is the correct one.

Set the owner property like:

secondarywindow.Owner = parent;

AND set TopMost to false.

Edwardoedwards answered 29/9, 2022 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.