Reputation: 1527
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?
Upvotes: 1
Views: 5626
Reputation: 474
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!
Upvotes: 0
Reputation: 96702
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.
Upvotes: 4
Reputation: 1972
It may use windows theme, in which indeterminate progress bars are not shown correctly.
Upvotes: 0