This has to be the simplest question of all, but I cannot seem to figure it out. I have the progress bar in place. How do I make it show progress? How do I start the thing?<
A possible workaround of the problem is to simply show or hide the ProgressBar control:
progressBar.Visibility = Visibility.Visible;
progressBar.Visibility = Visibility.Collapsed;
Apparently in some environments Height has to be set explicitly for indeterminate animation to run, while on others it is not needed.
If you set IsIndeterminate to True, the progress has the meaning that something is in progress but you cannot determine the exact duration. So, I can only tell you to set it to false and to use the progress bar in its "standard" behavior.
Also make sure that CacheMode="BitmapCache" is not set to your page - otherwise the animation will not run. It just displays the cached bitmap...
Simply put if you are trying to make the progress bar start, but as an indeterminate bar, then you must set the property IsIndeterminate to true when ready and to false when finished.
So in other words:
pbar.IsIndeterminate = true; //This starts your bar's animation
pbar.IsIndeterminate = false; //This stops your bar's animation
To give you context as to why you would want to do it this way look at the following psuedo code:
//Some method that is going to start something that is going to take a while
public void StartLongRunningProcess()
{
//Make a call to a web service asynchronously etc...
//Start the animation for your progress bar
pbar.IsIndeterminate = true;
}
//The method (delegate) that handles the result, usually from an event.
//This method will handle the result of the asynchronous call
public void HandlerForLongRunningProcess()
{
//Do stuff with result from your asynchronous web service call etc...
//Stop the animation for your progress bar
pbar.IsIndeterminate = false;
}
Let me be the first to say that I am not sure if this is the intended usage of this property, but I can say it definitely works.
This is no real difference than @dyslexicanaboko above, but it is quick and easy to do for a demonstration you can control:
In XAML:
<Button Content="Start Process" HorizontalAlignment="Center" Click="StartAProcess"/>
<Button Content="Stop Process" HorizontalAlignment="Center" Click="StopAProcess"/>
<ProgressBar Name="pBar1" Height="20"/>
In code behind:
Public Sub StartAProcess()
pBar1.IsIndeterminate = True
End Sub
Public Sub StopAProcess()
pBar1.IsIndeterminate = False
End Sub
Upon clicking the Start Process button the animation will start and continue until the Stop Process button is clicked. It should be obvious, but the IsIndeterminate option is not good UI practice; better to actually update the value, but for those who want to see this in action...