如何重置WPF进度条?

时间:2009-12-20 16:05:32

标签: wpf progress-bar reset

我正在测试WPF进度条并尝试将其重置为初始状态,但它不起作用。

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;

在动画之前,进度条是静态的(没有动画)。 动画后,进度条颜色现在为浅灰色(比之前更亮),具有增亮的闪光效果。

评论持续时间和双重动画时,进度条保持静态。我看到这与双动画有关。

//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;

如何解决此DoubleAnimation问题?我在这里缺少什么?

2 个答案:

答案 0 :(得分:1)

看一下这个帖子:

How to stop an animation in C# / WPF?

答案 1 :(得分:0)

使用DoubleAnimation的这种形式

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

您明确设置from和too值而不仅仅是目标值。

代码:

在窗口ctor中:

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

然后在按钮单击处理程序

中说
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);

PB在StackPanel中,xaml是

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

这最初是在XP上测试的,但见下文

对于Win 7解决方案,请参阅此处

link text