屏幕从睡眠中唤醒后,WPF应用程序窗口未完全刷新 [英] WPF Application windows does not fully refreshed after screen awakes from sleep

查看:397
本文介绍了屏幕从睡眠中唤醒后,WPF应用程序窗口未完全刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我们在一个WPF应用程序中发现了一个奇怪的问题,我们不确定如何处理它.当我们在其中一台笔记本电脑上运行该软件时,如果没有用户交互,屏幕会在一段时间后进入睡眠状态(变黑).它的应用程序本身仍在忙于从Internet下载数据并填充数据库中的表.还有一个进度栏和一个状态栏.
如果仅通过移动鼠标唤醒屏幕,程序将再次显示,但窗口的某些部分不会刷新.即使过程已完成并且状态栏也不正确,进度条仍会显示值.
从现在开始,您可以像没有任何动作一样使用该程序,但是只有将任务栏的整个窗口最小化并再次最大化时,进度栏和状态栏才会重绘.或者,如果您启动另一个也将使用进度栏或状态栏的操作.
这种奇怪的行为引起了很多混乱,因为在屏幕从睡眠中唤醒后,显示的数据似乎是错误的,并且您需要最小化和最大化窗口以查看实际情况.

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?

推荐答案

您需要处理事件Microsoft.Win32.SystemEvents.PowerModeChanged,请参见 ^ ].

查看以下代码示例: http://msdn.microsoft.com/en-us/library/hxkc1kwd. aspx [ ^ ].

要刷新WPF窗口,请尝试调用System.Windows.Window.UpdateLayout,请参见 http://msdn. microsoft.com/en-us/library/system.windows.window.aspx [
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


这篇关于屏幕从睡眠中唤醒后,WPF应用程序窗口未完全刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆