如何在Windows Phone 8.1中检测到屏幕被锁定/解锁?

时间:2014-10-29 12:59:02

标签: c# windows-runtime windows-phone-8.1 lockscreen

当用户在使用应用程序时锁定屏幕时,我想处置相机和其他资源。还想在解锁时重新初始化它。我的初步搜索给了我这些结果,这些结果适用于Windows Phone 8.我如何为Windows Phone 8.1做同样的事情?

请注意,我不想阻止屏幕被锁定。我只想知道屏幕锁定/解锁时引发的事件。

Windows Phone 8 detect screen unlock

ApplicationIdleDetectionMode for windows phone 8.1?

Idle detection for Windows Phone 8

1 个答案:

答案 0 :(得分:2)

您可以订阅Window.Current.VisibilityChanged:

Window.Current.VisibilityChanged += CurrentWindow_VisibilityChanged;

然后执行:

private async void CurrentWindow_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
    if (e.Visible)
    {
        // window visible... 
    }
    else
    {
        // window not visible, dispose and do what else needs to be done :)
    }
}