detect when screen turns off in windows phone

2019-06-13 19:24发布

Is there any way to detect when the screen turns off in the windows phone? It is possible to make the application run when this happens?

1条回答
Evening l夕情丶
2楼-- · 2019-06-13 19:39

You should set ApplicationIdleDecectionMode to Enabled and handle Obscured and Unobscured events of root frame:

Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Enabled;
      var rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
      if(rootFrame != null)
      {
        rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
        rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
      }

Look more at this article

查看更多
登录 后发表回答