I'm using progress bar of WPF (C#) to describe the process's progress.
My algorithm is below:
DoSomethingCode1();
ProgressBar.SetPercent(10); // 10%
DoSomethingCode2();
ProgressBar.SetPercent(20); // 20%
...
DoSomethingCode10();
ProgressBar.SetPercent(100); // 100%
It's ok, but it will make the progress bar was not sequent.
Someone can tell me some suggestions that make the progress bar is updated softly?
Check if you can modify the style of the progressbar and set an Easing function to it's storyboard that modifies the "filling" of the progressbar and by doing that it will have a smooth transition.
try this out.
You could call the
BeginAnimation
method to animate theProgressBar
'sValue
property. In my example below, I used aDoubleAnimation
.I created an extension method that takes in the desired percentage:
So in your code you could simply call:
Doing this simply smooths out the transition so it looks nicer. To quote another answer: "The idea is that a progress bar reports actual progress - not time elapsed. It's not intended to be an animation that just indicates something is happening." However, the default style of the progress bar does have a pulsating effect which can imply work is happening.
You can use a behavior!
Your XAML would look like this:
Whenever the
Progress
property you are binding to in the xaml changes, the code in the ProgressBarSmoother behavior will run, adding the animation to the progress bar for you with the appropriate values forTo
andFrom
!