2

我正在测试 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 问题?我在这里想念什么?

4

2 回答 2

1

看看这个线程:

如何在 C#/WPF 中停止动画?

于 2009-12-20T16:40:59.457 回答
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 上测试的,但见下文

For a Win 7 solution please see here

link text

于 2009-12-20T17:14:34.997 回答