wpf关闭窗口刷新页面_屏幕从睡眠状态唤醒后,WPF应用程序窗口无法完全刷新

Today we found a little strange problem in one of our WPF application and we are not exactly sure how to deal with it. When we run the software on one of our laptops the screen goes to sleep (turns black) after a while when there is no user interaction. It application itself is still busy downloading data from the internet and filling tables in a database. There is also a progress bar and a status bar.

If we wake the screen simply by moving the mouse the program is shown again but some parts of the window are not refreshed. The progress bar is still showing values even if the process is completed and the status bar is also wrong.

From this time on you can work with the program like nothing happened but progress bar and status bar will only be redrawn if you minimize the complete window to the task bar and maximize it again. Or if you start another action that will also use progress bar or status bar.

This strange behavior caused a lot of confusion because the displayed data seems to be wrong after the screen awakes from sleep and you need to minimize and maximize the window to see what is really going on.

What is wrong here?

解决方案You need to handle the event Microsoft.Win32.SystemEvents.PowerModeChanged, see http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents(v=VS.100).aspx[^].

Look at this code sample: http://msdn.microsoft.com/en-us/library/hxkc1kwd.aspx[^].

For refreshing of the WPF Window try to call System.Windows.Window.UpdateLayout, see http://msdn.microsoft.com/en-us/library/system.windows.window.aspx[^].

Thank you for the interesting question again.

Good luck,

—SA

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值