我的 win8.1 商店应用程序将用户导航到网络浏览器。用户可以与浏览器交互,但当他们返回到我的应用程序时,我需要它检测到这一点,以便它可以刷新其内容(并考虑在服务器上所做的任何更改)。
如果浏览器以全屏模式启动,这很容易,但在分屏时,我需要检测用户何时点击我的应用程序窗口。 (貌似默认是分屏启动的,其实是比较喜欢的体验)。
-------------------------------
| | |
| | |
| my app | browser |
| | |
| | |
-------------------------------
问题 - 我可以使用什么事件来检测用户点击以将焦点从浏览器更改到我的应用程序的时间?
我为页面尝试了 GotFocus,但没有被调用...
请您参考如下方法:
您似乎要查找的事件是 Window.Activated :
This event occurs when a Window has been activated or deactivated by the system. An app can determine what the status of the Window activation is by checking the WindowActivatedEventArgs.WindowActivationState property. A Window could be visible on screen but not be active (for example, in snapped apps). Additionally, if any other parts of the system takes focus away from the window, this event will occur. This could happen as a result of user interaction or code, and the WindowActivationState will indicate which action has taken place.
请注意,当窗口和 失去焦点时将触发此事件。因此,您必须测试事件参数以确定发生了什么。
您可以使用Window.Current 获取当前窗口的实例。 .