开发者

WPF-Window Topmost for own application only?

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 sw开发者_C百科itch 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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜