WPF等待光标BackgroundWorker的主题 [英] WPF Wait Cursor With BackgroundWorker Thread

查看:268
本文介绍了WPF等待光标BackgroundWorker的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示沙漏光标和禁用窗口,而一个BackgroundWorker进程运行在另一个线程。

I want to show the hourglass cursor and disable the window while a BackgroundWorker process runs in another thread.

这是我在做什么:

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?

这似乎根据这个问题工作 vg1890 :<一href="http://stackoverflow.com/questions/273809/disabling-all-but-one-control-in-a-wpf-window">Disabling所有,但在一个WPF窗口一个控制

It seems to work for vg1890 according to this question: Disabling all but one control in a WPF window

推荐答案

什么似乎发生在这里的是,WPF是忽略了光标的残疾人窗口设置。以下解决方法似乎工作:而不是禁用窗口本身,禁用的内容窗口的:

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#:

((UIElement)Content).IsEnabled = false;
Cursor = Cursors.Wait;

// and in RunWorkerCompleted handler:
((UIElement)Content).IsEnabled = true;
Cursor = Cursors.Arrow;

Visual Basic中:

Visual Basic:

DirectCast(Content, UIElement).IsEnabled = False
Cursor = Cursors.Wait

' and in RunWorkerCompleted handler:'
DirectCast(Content, UIElement).IsEnabled = True
Cursor = Cursors.Arrow

这篇关于WPF等待光标BackgroundWorker的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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