C#:为什么我的ProgressBar没有多次运行?

时间:2014-04-07 08:32:21

标签: c# wpf progress-bar

我想在我的WPF应用程序中实现2个进度条。一个(ProgressbarDocument)应显示每个所选文档的进度,另一个(ProgressbarProcess)应显示整个过程的进度,包括对每个所选文档的处理。 我的问题是,如果进度条的值为100,则进度条的动画会停止,但ProgressbarDocument的动画不会重置并重新启动。 我怎么能这样做?

double summand = (1 / anzahl);

Duration durationdocument = new Duration(TimeSpan.FromSeconds(1));
Duration durationprocess = new Duration(TimeSpan.FromSeconds(anzahl));

DoubleAnimation doubleanimationdocument = new DoubleAnimation(ProgressbarDocument.Value, durationprocess);
DoubleAnimation doubleanimationprocess = new DoubleAnimation(ProgressbarProcess.Value, durationprocess);

for (int j = 0; j <= anzahl; j++ )
{
   for (int i = 0; i < 100; i++)
   {
      ProgressbarDocument.Value++;
      ProgressbarProcess.Value= summand + ProgressbarProcess.Value;

      doubleanimationdocument = new DoubleAnimation(ProgressbarDocument.Value, durationdocument);
      doubleanimationprocess = new DoubleAnimation(ProgressbarProcess.Value, durationprocess);
      ProgressbarDocument.BeginAnimation(ProgressBar.ValueProperty, doubleanimationdocument);
      ProgressbarProcess.BeginAnimation(ProgressBar.ValueProperty, doubleanimationprocess);
   }
   if(ProgressbarDocument.Value==100)
   {
      ProgressbarDocument.Value = 0;
      ProgressbarDocument.BeginAnimation(ProgressBar.ValueProperty, doubleanimationdocument);
   }
}

1 个答案:

答案 0 :(得分:0)

你的内部for循环for (int i = 0; i < 100; i++)将在我99之后退出。永远不会调用i == 100,因此你的if语句if(ProgressbarDocument.Value==100)永远不会匹配。

我假设你希望你的for循环运行到100:

for (int i = 0; i <= 100; i++)