本文介绍了[UWP]应用失败并重新获得焦点的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个winJS通用Windows 10应用程序。每当应用程序失去焦点时我想暂停视频,并在视频重新获得焦点时取消暂停。是否有我应该监听的事件?

I have created a winJS universal Windows 10 app. I would like to pause a video whenever the app loses focus and unpause when the video regains focus. Are there events that I should be listening for?

推荐答案

Window.Current.Activated += Current_Activated;




然后,检测事件处理程序中的状态:

Then, detect the state in the event handler:

void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
        {
            if (e.WindowActivationState ==
                Windows.UI.Core.CoreWindowActivationState.Deactivated)
            {
                FocusStatus.Text = "Focus lost!";

            }
            else if (e.WindowActivationState ==
                Windows.UI.Core.CoreWindowActivationState.PointerActivated)
            {
                FocusStatus.Text = "App has focus from clicking";
            }
            else if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.CodeActivated)
            {
                FocusStatus.Text = "App has focus from the OS";
            }
        }

我刚刚写了一篇关于这个主题的博客文章,内容更详细,包括检测应用程序的时间是可见/不可见的:

I just wrote a blog post about this topic with more detail, including detecting when the app is visible/invisible:

http://grogansoft.com/blog/?p=1269

http://grogansoft.com/blog/?p=1269


这篇关于[UWP]应用失败并重新获得焦点的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:29