WPF - 将窗口置于前面窗口、WPF

2023-09-05 23:02:57 作者:樱花祭

我有一个WPF的窗口,我不要靠近。相反,我隐藏()和show()它。现在,当我双击在我的上一个记录,一个网格主窗口将触发展()的窗口时,窗口会一直显示在主窗口的后面。 我已经试过了休耕,但没有成功:

I have a WPF-Window which I don't close. Instead I do Hide() and Show() it. Now, when I doubleclick in my MainWindow in a Grid on a Record, which will Trigger to Show() the Window, the Window will always be shown behind the MainWindow. I have tried the fallowing, but with no success:

view.Show();
view.Activate();
view.Topmost = true;
view.Topmost = false;
view.Focus();       

有另一种方式,我可以用它来使窗口绝对在前面?我不能设置主窗口的所有者。

Is there another way which I can use to bring the window absolut to the front? I cannot set the MainWindow as the Owner.

推荐答案

Window.Activate是要走的路(如果你不想设置为所有者)。如果这不能正常工作(如你所说),还有在其他位置上的错误。 也许你的主窗口已最顶层设置为?或者你有关注你的主窗口或在?控制递延通话

Window.Activate is the way to go (If you dont want to set to owner). If this does not work (as you describe), there is an error at another location. Maybe your MainWindow has TopMost set to true ? Or you have a deferred call that focuses your main window or a control within?

调用的ShowDialog()所建议的另一种答案是不是一种选择,除非你想整个应用程序被阻塞,直到模式打开的窗口被关闭。

Calling ShowDialog() as proposed in another answer is not an option unless you want that the whole app is blocked until the modal opened window is closed.

有一个error在Win32-API,它也影响了窗口管理,如果WPF,但你的问题的描述听起来并不像这样。

There is an error in the Win32-Api that influences also the window-management if WPF, but the description of your problem does not sound like this.

此外在这里是一个黑客,但我希望你不需要它:

Additionally here a hack, but I hope that you don't need it:

Dispatcher.BeginInvoke(new Action(delegate {       
        view.Activate();
        }), System.Windows.Threading.DispatcherPriority.ContextIdle, null);