从页面和窗口调用窗口恢复焦点-WPF [英] Call a Window from a Page & restore focus - WPF

查看:54
本文介绍了从页面和窗口调用窗口恢复焦点-WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我目前正在使用Pages开发WPF NavigationApplication.现在,我打算使用http://multitouchvista.codeplex.com/将Multitouch集成到某些页面中.现在,Multitouch Vista非常棒,但只允许在Windows中使用,而不能在页面中使用.

我需要一些有关如何从页面调用窗口以及如何关闭窗口并将焦点重新分配给页面的帮助.
这是我到目前为止所管理的:

来自页面:
Window1 w = new Window1;
w.Show();
w.Focus();

然后在关闭窗口时(这没用)(问题是关闭窗口后页面没有焦点)

this.Close();
Application.Current.MainWindow.Activate();
Application.Current.MainWindow.Focus();
Application.Current.MainWindow.Show();



我还尝试在窗口构造函数中请求一个页面,以便我可以简单地执行.show()& amp; amp; .focus(),但都没有用.

反正还有吗?

谢谢
Daniel

Hi all,

I''m currently developing a WPF NavigationApplication using Pages. Now, I was going to incorporate Multitouch in some pages using http://multitouchvista.codeplex.com/ . Now Multitouch vista is great but it only allows that in Windows and not pages.

I need some help on how to call the window from the page, and the how to close it and give back the focus to the page.
This is what I''ve managed so far:

From Page:
Window1 w= new Window1;
w.Show();
w.Focus();

Then when closing the window (this is what didnt work)(the issue is that the Page has No Focus once the window is closed)

this.Close();
Application.Current.MainWindow.Activate();
Application.Current.MainWindow.Focus();
Application.Current.MainWindow.Show();



I''ve also tried to ask for a page in the window constructor so that i would have that same page instance th i would simple do .show() & .focus() but both didn''t work.

Is there anyway around this?

Thanks
Daniel

推荐答案

Xihadd写道:

Window1 w = new Window1;
w.Show();
w.Focus();

Window1 w= new Window1;
w.Show();
w.Focus();



您的问题是您正在呼叫表演,这是无模式的.您应该首先在w上挂接一个事件,以便关闭该事件后,将调用主应用程序中的代码. this.Close()关闭窗口,我不确定其余代码是否已运行,并且无论哪种方式,使用MainWindow都是一种真正的技巧,当您可以对其进行更优雅的设置时.我将把一个本地方法挂接到formclosed事件上,看看它是如何工作的.该方法可以为您重置焦点,实际上,它可能是您只是内联编写的匿名方法.



Your issue is that you''re calling show, which is modeless. You should first hook up an event on w, so that when it is closed, code in the main app is called. this.Close() closes the window, I am not sure that the rest of the code is run, and, either way, using the MainWindow is a real hack when you could set it up more elegantly. I would hook a local method to the formclosed event, and see how that works. That method can reset the focus for you, in fact, it could be an anonymous method that you just write inline.


这篇关于从页面和窗口调用窗口恢复焦点-WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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