UWP: Detect app gaining/losing focus

前端 未结 4 998
忘了有多久
忘了有多久 2020-12-16 20:20

I want to be able to prevent the screen saver from triggering while my app is in use by using the DisplayRequest class, but I only want to do this while it\'s the active app

4条回答
  •  感动是毒
    2020-12-16 20:57

    It's actually quite simple:

    Window.Current.Activated += Current_Activated;
    
    private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
    {
        if (e.WindowActivationState == CoreWindowActivationState.Deactivated)
        {
            // do stuff
        }
        else
        {
            // do different stuff
        }
    }
    

提交回复
热议问题