简体   繁体   中英

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

I want to implement 2 progress bars into my WPF-application. 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. 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. 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.

I assume you wanted your for loop to run until 100:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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