2

I'm testing a WPF progress bar and trying to reset it to its initial state, but it doesn't work.

Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
myProgress.IsIndeterminate = true;
myProgress.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
myProgress.Value = 0;

Before animation, the progress bar is static (no animation). After animation, the progress bar color is now light gray (lighter than before) with a brightening flash effect.

When commenting duration and double animation, the progress bar remains static. I see there's something to do with this double animation.

//Duration duration = new Duration(TimeSpan.FromSeconds(1));
//DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);
myProgress.IsIndeterminate = true;
//myProgress.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
myProgress.Value = 10;
myProgress.Value = 0;

How can I solve this DoubleAnimation issue? What am I missing here?

Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161

2 Answers2

1

Have a look at this thread:

How to stop an animation in C# / WPF?

Community
  • 1
  • 1
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
0

Use this form of the DoubleAnimation instead

DoubleAnimation doubleanimation = new DoubleAnimation(0,200, duration);

Where you explicitly set both a from and too value rather than just a destination value.

Code:

Within the window ctor:

myProgress.Maximum = 100; myProgress.Minimum = 0;

Then say in a button click handler

myProgress.IsIndeterminate = false; //shouldn't really need this PB oddity
myProgress.IsIndeterminate = true;
myProgress.Value = 0;

Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation doubleanimation = new DoubleAnimation(0,200, duration);

myProgress.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);

The PB is in a StackPanel, xaml is

<ProgressBar Name="myProgress" Height="20"></ProgressBar>

This was initially tested on XP but see below

For a Win 7 solution please see here

link text

Community
  • 1
  • 1
Andrew
  • 2,598
  • 16
  • 27
  • Ok, but the gray flashing glow effect doesn't go away. It's still there. – Junior Mayhé Dec 20 '09 at 17:21
  • I am having trouble reproducing the glow effect you talk about. Have you set any other values elsewhere on the ProgressBar? – Andrew Dec 20 '09 at 17:42
  • The other thing to try is in your code toggle the IsIndeterminate to false then in the next line set it back to true, does that help? – Andrew Dec 20 '09 at 17:44
  • I already uploaded the video on http://www.youtube.com/watch?v=HQtGA_AW05U you can see it in a few minutes. Progress bar is with its default values (I have not changed its properties). – Junior Mayhé Dec 20 '09 at 18:25
  • Ok I will check it out once Youtube have processed it. – Andrew Dec 20 '09 at 18:32
  • I see the effect, I am somewhat mystified - looks like it is not resetting a style - what OS are you running this on I am using XP? – Andrew Dec 20 '09 at 18:55
  • 1
    Just tried this on Windows 7 - I don't like that glow - see this post which appears to solve it, http://stackoverflow.com/questions/1523217/wpf-windows-7-disable-default-progress-bar-glow-animation – Andrew Dec 20 '09 at 19:16
  • Thank you Andrew, perhaps we should sent it to Visual Studio 2010 team?! – Junior Mayhé Dec 20 '09 at 19:24
  • You are welcome - yes good idea - Just added an update to my answer. I have already reported another issue with the dreaded PB where you cannot reset the max values http://stackoverflow.com/questions/1852647/is-this-wpf-progressbar-odd-render-behaviour-a-bug – Andrew Dec 20 '09 at 19:56