簡體   English   中英

如何使用WPF進度條?

[英]How to use the WPF progressbar?

我試圖使用WPF進度條控件,並將IsIndeterminate屬性設置為true。 我遇到的問題是它沒有得到更新。

我正在做這樣的事情:

pbProgressBar.Visibility = Visibility.Visible; 
//do time consuming stuff
pbProgressBar.Visibility = Visibility.Hidden;

我試圖將其包裝在一個線程中,然后使用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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM