问题
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.
回答1:
You can try to use the "Owner" property of the window, with that the splash screen will always overlap the other windows.
回答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:
- Show MainWindow empty or bare bones (empty fields/grid etc)
- Launch async load method to get data and populate main window
- Create splash screen, set owner to self and show
- make sure to close splash screen when load is complete.
that should keep the splash on top while load is being processed.
来源:https://stackoverflow.com/questions/2463149/wpf-window-topmost-for-own-application-only