WPF 等待游标与后台工作线程
我想在 BackgroundWorker 进程在另一个线程中运行时显示沙漏光标并禁用窗口。
这就是我正在做的:
Private Sub MyButton_Click(...)
Dim box As New AnotherWpfWindow()
box.Owner = Me
...
box.ShowDialog()
If (box.DialogResult.GetValueOrDefault = True) Then
Me.IsEnabled = False
Me.Cursor = Cursors.Wait
MyBackgroundWorker.RunWorkerAsync()
End If
End Sub
Private Sub MyBackgroundWorker_RunWorkerCompleted(...)
UpdateInterface()
Me.IsEnabled = True
Me.Cursor = Cursors.Arrow
End Sub
窗口像我想要的那样被禁用,但光标仍然是箭头。 如何使其成为等待光标?
根据这个问题,它似乎适用于 vg1890:禁用 WPF 窗口中除一个控件之外的所有控件
I want to show the hourglass cursor and disable the window while a BackgroundWorker process runs in another thread.
This is what I'm doing:
Private Sub MyButton_Click(...)
Dim box As New AnotherWpfWindow()
box.Owner = Me
...
box.ShowDialog()
If (box.DialogResult.GetValueOrDefault = True) Then
Me.IsEnabled = False
Me.Cursor = Cursors.Wait
MyBackgroundWorker.RunWorkerAsync()
End If
End Sub
Private Sub MyBackgroundWorker_RunWorkerCompleted(...)
UpdateInterface()
Me.IsEnabled = True
Me.Cursor = Cursors.Arrow
End Sub
The window becomes disabled like I want, but the cursor remains an arrow. How can I make it the Wait cursor?
It seems to work for vg1890 according to this question: Disabling all but one control in a WPF window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种方法是全局更改光标,是..
Another way is to change the cursor globally, is..
这里发生的情况似乎是 WPF 忽略了禁用窗口上的光标设置。 以下解决方法似乎有效:不要禁用窗口本身,而是禁用窗口的内容:
C#:
Visual Basic:
What seems to be happening here is that WPF is ignoring the Cursor setting on the disabled window. The following workaround seems to work: instead of disabling the window itself, disable the content of the window:
C#:
Visual Basic: