user3441937
user3441937

Reputation:

How I can create animation in Xamarin.Forms using MVVM

I want to create an animation triggered when pressing the icon

How I can i do it in while following the MVVM pattern.

View

<Image Source="ic_test.png" HorizontalOptions="Center" VerticalOptions="Start" Margin="16,24,16,0">
  <Image.GestureRecognizers>
      <TapGestureRecognizer Command="{Binding AnimationTestCommand}" />
  </Image.GestureRecognizers>
</Image>

Upvotes: 2

Views: 1696

Answers (1)

Ziyad Godil
Ziyad Godil

Reputation: 2680

You need to create a custom Image and put animation on tap like below:

public class CustomImage : Image
{
    public CustomImage() : base()
    {
        const int _animationTime = 10;
        var iconTap = new TapGestureRecognizer();
        iconTap.Tapped += async (sender, e) =>
        {
            try
            {
                var btn = (CustomImage)sender;
                await btn.ScaleTo(5, _animationTime);
                //await btn.ScaleTo(1, _animationTime);
            }
            catch (Exception ex)
            {
                ex.Track();
            }
        };

    }
}

Upvotes: 2

Related Questions