简体   繁体   English

窗口最顶端的混乱 - 没有出路?

[英]Window topmost confusion - and no way out?

In my WPF application I have a fullscreen MainWindow . 在我的WPF应用程序中,我有一个全屏MainWindow From The MainWindow the user can open a PreviewWindow . MainWindow中 ,用户可以打开PreviewWindow The PreviewWindow is a modal window so it is on top of the MainWindow. PreviewWindow是一个模态窗口,因此它位于MainWindow之上。 So far so good. 到现在为止还挺好。

Still the user is able to select the MainWindow from the Windows Taskbar while the PreviewWindow is open. PreviewWindow打开时,用户仍然可以从Windows任务栏中选择MainWindow Then the PreviewWindow is hidden under the MainWindow but the MainWindow is inavtive since the PreviewWindow is still the only active window. 然后PreviewWindow隐藏在MainWindow下,但MainWindow是不可用的,因为PreviewWindow仍然是唯一的活动窗口。 For the user it looks like the application is not responding anymore. 对于用户来说,应用程序似乎不再响应。

I don't know why my users work like that but they do and it causes a lot of confusion. 我不知道为什么我的用户会像那样工作,但他们这样做会导致很多混乱。

Our first solution was the make the PreviewWindow topmost but that did not help much. 我们的第一个解决方案是使PreviewWindow最顶级,但这并没有多大帮助。 From the PreviewWindow the user can open a SaveDialog . 用户可以从PreviewWindow打开SaveDialog But with the PreviewWindow topmost the SaveDialog is hidden under the PreviewWindow . 但是使用PreviewWindow最顶层的SaveDialog隐藏在PreviewWindow下

My idea is to make the PreviewWindow topmost untill the user opens the SaveDialog . 我的想法是使PreviewWindow最高,直到用户打开SaveDialog And make it topmost again after the SaveDialog has endet. SaveDialog尝试之后再次使它成为最顶层。

Is this the only way to do it? 这是唯一的方法吗? Is there a way to bring a modal window back to top when its parent window is choosen? 有没有办法在选择父窗口时将模态窗口置回顶部?

Two things: 两件事情:

  1. Make sure your PreviewWindow has ShowInTaskbar set to False . 确保您的PreviewWindow将ShowInTaskbar设置为False
  2. Set PreviewWindow.Owner = MainWindow and then try with both Show() and ShowDialog() . 设置PreviewWindow.Owner = MainWindow ,然后尝试使用Show()ShowDialog()

If it is a modal window, you should be displaying it using Window.ShowDialog() . 如果是模态窗口,则应使用Window.ShowDialog()显示它。

Is there some reason you cannot do that? 你有什么理由不能那样做吗?

Other answers are not complete or relevant. 其他答案不完整或相关。 Sorry guys ;) 对不起大家 ;)

Use ShowDialog() in order to wait end of second window before continuing with first window. 在继续第一个窗口之前,使用ShowDialog()以等待第二个窗口结束。 Use Owner property to link windows. 使用Owner属性链接窗口。

   previewWindow = new Window2();
   previewWindow.Owner = this;
   previewWindow.ShowDialog();

That's work with 3 or more windows if you want (w1 launch w2, w2 launch w3, ...). 如果你需要(w1启动w2,w2启动w3,......),那就可以使用3个或更多窗口。 When selecting first window in taskbar, all windows will appear. 在任务栏中选择第一个窗口时,将显示所有窗口。

You don't need to set TopMost or ShowInTaskbar properties (but you can if you want particular behaviour) 您不需要设置TopMost或ShowInTaskbar属性(但如果您想要特定的行为,则可以)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM