views:

674

answers:

2

Hello guys

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?

+1  A: 

Have a look at this thread:

http://stackoverflow.com/questions/20298/how-to-stop-an-animation-in-c-wpf

Tony
Yes I was there. I'm not using StoryBoard, but just c# code to test if this gray glow effect disappears.
Junior Mayhé
Indeed it's a problem with OS
Junior Mayhé
A: 

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

Andrew
Ok, but the gray flashing glow effect doesn't go away. It's still there.
Junior Mayhé
I am having trouble reproducing the glow effect you talk about. Have you set any other values elsewhere on the ProgressBar?
Andrew
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
I already uploaded the video on http://www.youtube.com/watch?v=HQtGA_AW05Uyou can see it in a few minutes. Progress bar is with its default values (I have not changed its properties).
Junior Mayhé
Ok I will check it out once Youtube have processed it.
Andrew
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
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
Yes it's Windows 7!
Junior Mayhé
Thank you Andrew, perhaps we should sent it to Visual Studio 2010 team?!
Junior Mayhé
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