Progressbar Animation controlled by Timer

Hello,

I struggle to understand the UI update process when I use the Xamarin forms timer.
I'm using the progressbar from Syncfusion and I want to animate it.
The interval is different from time to time (e.g. sometimes the progessbar should reload after 5 secondes, sometimes after 10).

I'm using

     progress.SetProgress(100, (int)totalSec * 1000, Easing.Linear);
    
Device.StartTimer(TimeSpan.FromSeconds(1), TimerElapsed);

to invoke a Xamarin Forms Timer and to start the first animation.

In the method TimerElapsed(), I try to reset the progessbar to 0 if the interval has ended. After that, the animation should start again:

    progressbar.SetProgress(0, 0, Easing.Linear);
    progressbar.SetProgress(100, (int)totalSec * 1000, Easing.Linear);

However, the progessbar is not resetted. I debugged the application and realized that the UI is only updated after TimerElapsed is finished. I have the feeling that the first SetProgress() call is somehow overridden by the second call. Is that right or do I misunderstand the functionality? How can I rewrite the process to solve this problem?

And I would like to implement a Start / Stop button. At the moment I am calculating the current progress when the stop button is clicked and I set the progress value to it. However, this results in little "jumps" to the actual value. Is there an easier and more precise way to stop the animation?

Thank you for your help!


3 Replies

MP Michael Prabhu M Syncfusion Team October 5, 2018 09:27 AM UTC

Hi Tamara, 

Thanks for contacting Syncfusion support. 

As you suspected, first SetProgress() overridden by the second call. We can resolve the problem by using the ValueChanged event, which is available in progressbar. We can able to reset the progress value in that event. We have prepared a sample to reach your requirement and the sample can be downloaded from the following location. 

To implement a Start / Stop button: 
When stop button is clicked, we can calculate the current progress of the progressbar by getting the value of “ActualProgressValue” property in progressbar. We have implemented a sample for your requirement and it can be downloaded from the following location. 

Thanks, 
Michael 



UN Unknown October 6, 2018 01:05 AM UTC

Thank you very much! Now it is working.


MP Michael Prabhu M Syncfusion Team October 8, 2018 04:03 AM UTC

Hi Tamara, 
 
Thanks for the update, feel free to contact us if you require any other assistance from us. 
 
Regards, 
Michael  



Loader.
Up arrow icon