[英]C# WPF PowerModeChanged doesn't work on Surface
Testing the code bellow in a non-surface device works just fine but when I try in a surface, I only get notifications when I remove the power cable ('statusChange' powerMode is triggered). 在非表面设备中测试下面的代码工作得很好但是当我在表面上尝试时,我只在取下电源线时才会收到通知('statusChange'powerMode被触发)。 Putting the surface in SLEEP the handler it's not called ('resume' and 'suspend' powerModes are not being trigged).
将表面置于SLEEP处理器中,它不会被调用('resume'和'suspend'powerModes没有被触发)。
Anyone knows why ? 谁知道为什么? Thank you.
谢谢。
Surface specs: 表面规格:
OS Name: Microsoft Windows 10 Pro 操作系统名称:Microsoft Windows 10 Pro
Version: 10.0.17134 Compilação 17134 版本:10.0.17134Compilação17134
OS Manufacturer: Microsoft Corporation OS制造商:Microsoft Corporation
System Manufacturer: Microsoft Corporation 系统制造商:Microsoft Corporation
System Model: Surface Pro 系统型号:Surface Pro
System Type: x64-based PC 系统类型:基于x64的PC
System SKU: Surface_Pro_1796 系统SKU:Surface_Pro_1796
Example [WPF Visual Studio Pro 2015] 示例[WPF Visual Studio Pro 2015]
MainWindow: 主窗口:
using System;
using System.Windows;
using Microsoft.Win32;
namespace WpfApplication2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
}
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
listView1.Items.Add(string.Format("{0} : Power mode changed = {1}", DateTime.Now, e.Mode));
}
}
}
XAML XAML
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication2"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<ListView x:Name="listView1" Margin="0">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
I am also working on such a problem. 我也在研究这个问题。 From what I've read, the Surface supports "Sleep state(Modern Standby)", or S0 low-power, and is not yet in actual sleep state (S1-3).
根据我的阅读,Surface支持“睡眠状态(现代待机)”或S0低功耗,并且尚未处于实际睡眠状态(S1-3)。 Pressing the power button or clicking the "sleep" option from the windows menu does not enter sleep directly but enters S0 low-power instead, thus not triggering PowerModeChanged.
按下电源按钮或从Windows菜单中单击“睡眠”选项不会直接进入睡眠状态,而是进入S0低功耗状态,因此不会触发PowerModeChanged。
https://docs.microsoft.com/en-us/windows/desktop/power/system-power-states#sleep-state-modern-standby https://docs.microsoft.com/en-us/windows/desktop/power/system-power-states#sleep-state-modern-standby
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.