简体   繁体   中英

WPF ProgressBar doesn't show progress

I am confused by WPF ProgressBar. Here is the code I have written to display it:

<ProgressBar Height="31" Margin="15" Name="progressBar" 
VerticalAlignment="Top" IsIndeterminate="True" />

As I know this is enough to make it work. But it doesn't work in my project. I mean when I show window (Popup actually as it's xbap project) progressbar doesn't show any animation, however it is visible.

There are no background threads yet, UI thread is not blocked.

What is wrong?

There are no background threads yet, UI thread is not blocked.

I think you have that exactly wrong, and that's your problem. You have no background threads, and thus your UI thread is blocked. If your method that updates the progress bar is running on the UI thread (which it is, if you're not running it on a background thread), updates to the progress bar won't appear until the method is done running and control is returned to the Dispatcher.

You need to run your long-running method on a background thread using a BackgroundWorker , and update the progress bar by raising and handling its ProgressChanged event. The event handler runs on the UI thread, and can update UI objects.

它可能使用Windows主题,其中不确定的进度条未正确显示。

Please try these codes

        ProgressBar test=new ProgressBar();
        Duration dr = new Duration(TimeSpan.FromSeconds(timespan));
        DoubleAnimation da = new DoubleAnimation(determination, dr);
        test.IsIndeterminate = false;
        test.Visibility = Visibility.Visible;
        test.BeginAnimation(ProgressBar.ValueProperty, da);

If you want the ProgressBar work,you should create an Animation instance,and set it to the ProgressBar.May it help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM