WPF-Window Topmost for own application only?

浪尽此生 提交于 2019-11-30 02:22:05

问题


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:

  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.



来源:https://stackoverflow.com/questions/2463149/wpf-window-topmost-for-own-application-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!