gpt4 book ai didi

c# - KeepScreenOnRequest.RequestActive 不工作

转载 作者:行者123 更新时间:2023-11-30 19:39:18 26 4
gpt4 key购买 nike

对于我的 Windows 应用商店应用程序,我希望我的应用程序始终处于事件状态。

我正在使用下面的代码。我的设备设置为在 10 秒内进入屏幕锁定,而当我使用我的应用程序时它仍然进入锁定屏幕。我是否错误地使用了这段代码?

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// Prevent tablet from sleeping while app is running
Windows.System.Display.DisplayRequest KeepScreenOnRequest = new Windows.System.Display.DisplayRequest();
KeepScreenOnRequest.RequestActive();
}

最佳答案

我认为您应该在页面导航事件而不是应用程序级事件上尝试...

using Windows.System.Display;

private DisplayRequest KeepScreenOnRequest;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if(KeepScreenOnRequest == null)
KeepScreenOnRequest = new DisplayRequest();

KeepScreenOnRequest.RequestActive();
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);

KeepScreenOnRequest.RequestRelease();
}

同样,在这种情况下,您必须分别处理所有应用页面上的请求和发布部分...

关于c# - KeepScreenOnRequest.RequestActive 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28140852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com