我试图使用WPF进度条控件,并将IsIndeterminate属性设置为true.我遇到的问题是它没有得到更新.
我正在做这样的事情:
pbProgressBar.Visibility = Visibility.Visible;
//do time consuming stuff
pbProgressBar.Visibility = Visibility.Hidden;
Run Code Online (Sandbox Code Playgroud)
我试图将其包装在一个线程中,然后使用Dispatcher对象进行调度.我应该如何解决这个问题:).
你必须做对的时候在后台线程消费的东西,你必须确保Visibility没有设置回Hidden,直到后后台线程做它的事.基本流程如下:
private void _button_Click(object sender, RoutedEventArgs e)
{
_progressBar.Visibility = Visibility.Visible;
new Thread((ThreadStart) delegate
{
//do time-consuming work here
//then dispatch back to the UI thread to update the progress bar
Dispatcher.Invoke((ThreadStart) delegate
{
_progressBar.Visibility = Visibility.Hidden;
});
}).Start();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8246 次 |
| 最近记录: |