Xamarin Forms ProgressBar Stop

对着背影说爱祢 提交于 2020-01-04 00:09:27

问题


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.


回答1:


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:




回答2:


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


来源:https://stackoverflow.com/questions/36149290/xamarin-forms-progressbar-stop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!