WPF - 将窗口置于前面 [英] WPF - Bring Window to Front

查看:1297
本文介绍了WPF - 将窗口置于前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.windows.window.activate.aspx">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.

有一个<一个href="http://stackoverflow.com/questions/3144004/wpf-app-loses-completely-focus-on-window-close">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);

这篇关于WPF - 将窗口置于前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆