WPF在进行中不更新文本框

Def*_*igh 4 wpf textbox progress

我有这个代码:

void wait(int ms)
{
    System.Threading.Thread.Sleep(ms);
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    info.Text = "step 1";
    wait(1000);
    info.Text = "step 2";
    wait(1000);
    info.Text = "step 3";
    wait(1000);
    info.Text = "step 4";
    wait(1000);
}
Run Code Online (Sandbox Code Playgroud)

问题是textbox.text在整个void button1_Click完成后更新.它没有在AIR上更新:(

拜托,怎么办?

Dea*_*alk 9

就这样做吧.

private void button1_Click(object sender, RoutedEventArgs e)
    {
        ThreadPool.QueueUserWorkItem((o) =>
             {
                 Dispatcher.Invoke((Action) (() => info.Text = "step 1"));
                 wait(1000);
                 Dispatcher.Invoke((Action) (() => info.Text = "step 2"));
                 wait(1000);
                 Dispatcher.Invoke((Action) (() => info.Text = "step 3"));
                 wait(1000);
                 Dispatcher.Invoke((Action) (() => info.Text = "step 4"));
                 wait(1000);
             });
    }
Run Code Online (Sandbox Code Playgroud)

  • 如果您可以添加为什么文本框值没有在播出中更新以及您的解决方案到底做了什么,那就太好了。 (2认同)