问题
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