Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms ProgressBar Stop

What is the best way to stop the progress bar animation in Xamarin Forms? Progress is started with:

animProgressBar = async () => { 
 ... 
 await progressBar.ProgressTo (0, 10000, Easing.Linear); 
 ... 
};

I would like to stop the animation and restart it. I have tried things like

progressBar.AbortAnimation("ProgressTo");

without success.

like image 639
Vladtn Avatar asked Sep 15 '26 11:09

Vladtn


2 Answers

I'm not sure that it is possible to cancel ProgressTo and I suppose that creating own animation is easiest solution:

new Button
{
    Text = "Kick progress bar",
    Command = new Command(() =>
    {
        if (progressBar.AnimationIsRunning("SetProgress"))
        {
            progressBar.AbortAnimation("SetProgress");
        }
        else
        {
            progressBar.Animate("SetProgress",(arg) => { progressBar.Progress = arg; }, 8*60, 8*1000, Easing.Linear);
        }
    })
}

Result:

enter image description here

like image 97
Mikalai Daronin Avatar answered Sep 17 '26 00:09

Mikalai Daronin


I'd like to suggest you to set progressBar.Progress = 0 to reset all progress. I made quick example:

Device.StartTimer(System.TimeSpan.FromMilliseconds(200), () =>
        {
            myProgressBar.Progress += 0.01;
            if (myProgressBar.Progress > .5)
            {
                myProgressBar.Progress = 0;
                return false;
            }

            return true;
        });
like image 30
Yehor Hromadskyi Avatar answered Sep 17 '26 00:09

Yehor Hromadskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!