Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimationDemoPage throws exception when clicking on the button during animation #1

Open
nicofr69 opened this issue Aug 31, 2017 · 0 comments

Comments

@nicofr69
Copy link

Hello David,

The AnimationDemoPage throws an exception when clicking on the button during animation:
System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.

I found how to inactivate the button during the animation:

<Button.Behaviors>
<behaviors:EventHandlerBehavior EventName="Clicked">

<behaviors:SetPropertyAction TargetObject="{x:Reference runAnimationButton}" PropertyName="IsEnabled" Value="false" />
<behaviors:SetPropertyAction TargetObject="{x:Reference stopAnimationButton}" PropertyName="IsEnabled" Value="true" />
<behaviors:SetPropertyAction TargetObject="{x:Reference stopAnimationButton}" PropertyName="IsVisible" Value="true" />
...

<behaviors:SetPropertyAction TargetObject="{x:Reference runAnimationButton}" PropertyName="IsEnabled" Value="true" />
<behaviors:SetPropertyAction TargetObject="{x:Reference stopAnimationButton}" PropertyName="IsEnabled" Value="false" />

But I did not find how to cancel the animation by clicking on the "Stop animation" button.
Here what I tried out:
Above code for stopAnimationButton plus:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:behaviors="clr-namespace:Behaviors;assembly=Behaviors"
x:Class="Behaviors.Sample.AnimationDemoPage"
x:Name="animationPage"
Title="Animation Demo"
Icon="xaml.png">

    <Button x:Name="stopAnimationButton" Text="Stop animation (ineffective)" IsVisible="true" IsEnabled="false">
        <Button.Behaviors>
            <behaviors:EventHandlerBehavior EventName="Clicked">
                <behaviors:InvokeMethodAction TargetObject="{x:Reference animationPage}" MethodName="OnStopAnimation" />
                <behaviors:SetPropertyAction TargetObject="{x:Reference runAnimationButton}" PropertyName="IsEnabled" Value="true" />
            </behaviors:EventHandlerBehavior>
        </Button.Behaviors>
    </Button>

	public void **OnStopAnimation**(object sender, EventArgs args)
	{
		//KO no animation.Commit(.., "animationID", ...) defined: this.AbortAnimation("animationID";
		//KO still same runtime exception: ViewExtensions.**CancelAnimations**(image);
		ViewExtensions.**CancelAnimations**(this); //KO: no effect (but no exception neither)
	}

Any idea?
Thanks.

Best regards,
Nikolas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant