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
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">
Any idea?
Thanks.
Best regards,
Nikolas