using Xamarin.Forms; using Xamarin.Forms.Xaml; using MobileAnimate; [ContentProperty("Child")] public class ButtonAnimator : ContentView { private Button Child => Content as Button; private Animation ViewAnimation; public ButtonAnimator() { ViewAnimation = new Animation(); Child.PropertyChanging += Child_PropertyChanging; } private void Child_PropertyChanging(object sender, PropertyChangingEventArgs e) { if (e.PropertyName == Button.WidthProperty.PropertyName || e.PropertyName == Button.HeightProperty.PropertyName) { AnimateView(); } } private void AnimateView() { var newWidth = Child.Width * 1.2; var newHeight = Child.Height * 1.2; ViewAnimation = new Animation(d => { Child.HeightRequest = d; Child.WidthRequest = d; }, newWidth, newHeight, Easing.SinInOut); ViewAnimation.Commit(this, "ScaleAnimation", length: 600); } }
using Xamarin.Forms; using Xamarin.Forms.Xaml; using MobileAnimate; [ContentProperty("Child")] public class ImageAnimator : ContentView { private Image Child => Content as Image; private Animation ViewAnimation; public ImageAnimator() { ViewAnimation = new Animation(); Child.PropertyChanging += Child_PropertyChanging; } private void Child_PropertyChanging(object sender, PropertyChangingEventArgs e) { if (e.PropertyName == Image.RotationProperty.PropertyName) { AnimateView(); } } private void AnimateView() { var newRotation = Child.Rotation + 360; ViewAnimation = new Animation(d => { Child.Rotation = d; }, Child.Rotation, newRotation, Easing.Linear); ViewAnimation.Commit(this, "RotationAnimation", length: 2000); } }This code creates a custom image animation by rotating the image by 360 degrees whenever the user interacts with it. Package library - Mobile Animate uses the Xamarin.Forms package library.