pbStatus.Value = 0;//Promblem!! pbStatus is a ProgressBar
Duration dr = new Duration(TimeSpan.FromSeconds(2));
DoubleAnimation da = new DoubleAnimation(100, dr);
pbStatus.IsIndeterminate = false;
pbStatus.Visibility = Visibility.Visible;
pbStatus.BeginAnimation(ProgressBar.ValueProperty, da);
答案 0 :(得分:4)
请参阅this article。
摘要:动画后设置值有三种方法。
(1)设置要停止的动画的填充行为:
da.FillBehavior = FillBehavior.Stop;
(3)在设置新值之前调用此动画来删除动画:
pbStatus.BeginAnimation(ProgressBar.ValueProperty, null);
答案 1 :(得分:1)
来自this article:
private void CreateDynamicProgressBarControl()
{
ProgressBar PBar2 = new ProgressBar();
PBar2.IsIndeterminate = false;
PBar2.Orientation = Orientation.Horizontal;
PBar2.Width = 100;
PBar2.Height = 10;
Duration duration = new Duration(TimeSpan.FromSeconds(10));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
PBar2.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
SBar.Items.Add(PBar2);
}