windows UWP保持屏幕常亮或关闭

转载:DisplayRequest


/// <param name="sender"></param> 
/// <param name="e"></param> 
private void Activate_Click(object sender, RoutedEventArgs e) 
{ 
    Error.Text = string.Empty; 
    Button b = sender as Button; 
    if (b != null) { 
        try { 
            if (g_DisplayRequest == null) { 
                // This call creates an instance of the displayRequest object 
                g_DisplayRequest = new DisplayRequest(); 
            } 
        } catch (Exception ex) { 
            rootPage.NotifyUser("Error Creating Display Request: " + ex.Message, NotifyType.ErrorMessage); 
        } 
 
        if (g_DisplayRequest != null) { 
            try { 
                // This call activates a display-required request. If successful,  
                // the screen is guaranteed not to turn off automatically due to user inactivity. 
                g_DisplayRequest.RequestActive(); 
                drCount += 1; 
                rootPage.NotifyUser("Display request activated (" + drCount + ")", NotifyType.StatusMessage); 
            } catch (Exception ex) { 
                rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage); 
            } 
        } 
    } 
}

/// <param name="sender"></param> 
/// <param name="e"></param> 
private void Release_Click(object sender, RoutedEventArgs e) 
{ 
    Error.Text = string.Empty; 
    Button b = sender as Button; 
    if (b != null) { 
        if (g_DisplayRequest != null) { 
            try { 
                // This call de-activates the display-required request. If successful, the screen 
                // might be turned off automatically due to a user inactivity, depending on the 
                // power policy settings of the system. The requestRelease method throws an exception  
                // if it is called before a successful requestActive call on this object. 
                g_DisplayRequest.RequestRelease(); 
                drCount -= 1; 
                rootPage.NotifyUser("Display request released (" + drCount + ")", NotifyType.StatusMessage); 
            } catch (Exception ex) { 
                rootPage.NotifyUser("Error: " + ex.Message, NotifyType.ErrorMessage); 
            } 
        } 
    } 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值