检测屏幕何时锁定 UWP [英] Detect when screen is locked UWP
本文介绍了检测屏幕何时锁定 UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 UWP 应用中检测屏幕是否被锁定?
How can I detect if the screen is locked in UWP apps?
当屏幕被锁定时,应用程序会暂停,我需要在锁定屏幕的情况下输入一些不同的代码.
When screen is locked, suspension of app occurs and I need to put some different code in case of locking screen.
推荐答案
您会在这里找到答案:https://developerinsider.co/prevent-the-screen-from-locking-on-uwp/
对于那些不寻找指向另一篇文章的链接的人来说,这里的摘要可能有用,也可能没有帮助
For those that are not looking for a link to another post that could, or could not, potentially be helpful here is the summary
您将使用的代码是
var displayRequest = new DisplayRequest();
displayRequest.RequestActive(); //to request keep display on
displayRequest.RequestRelease(); //to release request of keep display on
要记住的事情是
- 仅在需要时使用显示请求,即没有用户的时候需要输入,但显示应保持打开状态.例如,在全屏演示期间或当用户正在阅读电子书.
- 在不再需要时立即发布每个显示请求.
- 在应用暂停时释放所有显示请求.如果仍然需要显示器保持开启状态,则应用程序可以在重新激活时创建新的显示请求.
这篇关于检测屏幕何时锁定 UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文