简体   繁体   English

C#:为什么我的ProgressBar不能运行几次?

[英]C#: Why my ProgressBar doesn't run several times?

I want to implement 2 progress bars into my WPF-application. 我想在我的WPF应用程序中实现2个进度条。 One (ProgressbarDocument) shall show the progress of every chosen document and the other(ProgressbarProcess) shall show the progress of the whole process, that includes the treatment of every chosen document. 一个(ProgressbarDocument)应显示每个选定文档的进度,另一个(ProgressbarProcess)应显示整个过程的进度,包括对每个选定文档的处理。 My Problem is, that the animation of the progress bars stops if they have a value of 100, but the animation of ProgressbarDocument isn't reset and restarted. 我的问题是,如果进度栏的值为100,则动画会停止,但是ProgressbarDocument的动画不会重置并重新启动。 How can I do this? 我怎样才能做到这一点?

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);
   }
}

Your inner for loop for (int i = 0; i < 100; i++) will exit after i was 99. i == 100 is never called, thus your if-Statement if(ProgressbarDocument.Value==100) never matches. 您的for (int i = 0; i < 100; i++)内部for循环将在i为99后退出。i == 100不会被调用,因此您的if语句if(ProgressbarDocument.Value==100)永远不会匹配。

I assume you wanted your for loop to run until 100: 我假设您希望for循环运行到100:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM