WPF:当 UI 线程被阻止时更新鼠标指针
我有一些任务将 UI 冻结几秒钟,在这种特定情况下,我除了从 UI 线程执行它之外别无选择(通常我使用调度程序)。
我完全理解我的窗口在此期间无法重新绘制自身,但是如何在执行阻塞调用之前强制鼠标指针重新绘制自身?现在我这样做:
Me.Cursor = System.Windows.Input.Cursors.Wait
[Heavy Task]
Me.Cursor = System.Windows.Input.Cursors.Default
但是窗口不会将光标更新为等待光标,因为 UI 线程被冻结了?如何强制更新?
I have some task that's freezing the UI for a few seconds, and in this specific case I have no other choice than execute it from the UI thread (normally I use Dispatchers).
I completely understand that my window cannot repaint itself during this time, but how do I force the mousepointer to redraw itself before executing the blocking call? Right now I do:
Me.Cursor = System.Windows.Input.Cursors.Wait
[Heavy Task]
Me.Cursor = System.Windows.Input.Cursors.Default
But the window does not update the cursor to a wait-cursor, because the UI thread is frozen? How do I force the update?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我已经找到了解决方案。不要更改窗口的光标,而是全局覆盖它:
Seems I have found the solution. Instead of changing the cursor for the window, overide it globally: