Animations change how an element looks over a set amount of time, such as fading in a label or shaking a field. You define an animation once, then start it when the person does something or when the page loads. There are two kinds. Triggered animations run when something starts them. Passive animations stay attached to an element and update it whenever a value they track changes. Each animation has its own page, listed below. Defining Animations Define an animation in the Resources of an ancestor. Animations are referenced by name, so each one needs an x:Key and has to be defined on an element above the one that uses it. You can’t define it on the element itself. In this layout, an animation for myLabel can go on the VerticalStackLayout or the ScrollView: <ScrollView> <VerticalStackLayout> <Label x:Name="myLabel" Text="Hello Rock!" /> </VerticalStackLayout> </ScrollView> Here it’s defined on the VerticalStackLayout: <VerticalStackLayout> <VerticalStackLayout.Resources> <Rock:FadeToAnimation x:Key="FadeOut" Target="{x:Reference myLabel}" Duration="2000" Opacity="0" /> </VerticalStackLayout.Resources> <Label x:Name="myLabel" Text="Hello Rock!" /> </VerticalStackLayout> This animation targets myLabel and changes its Opacity from its current value to 0 over 2,000 milliseconds (2 seconds). Defining an animation doesn’t start it. Starting Animations Start an animation with a trigger or a behavior. A trigger starts it when the person does something, such as tapping a button. A behavior starts it automatically when the element loads. With a Trigger Add a BeginAnimation to an event trigger. When the person taps this button, the label fades out over 2 seconds: <ScrollView> <VerticalStackLayout> <VerticalStackLayout.Resources> <Rock:FadeToAnimation x:Key="FadeOut" Target="{x:Reference myLabel}" Duration="2000" Opacity="0" /> </VerticalStackLayout.Resources> <Label x:Name="myLabel" Text="Hello Rock!" /> <Button Text="Fade"> <Button.Triggers> <EventTrigger Event="Clicked"> <Rock:BeginAnimation Animation="{StaticResource FadeOut}" /> </EventTrigger> </Button.Triggers> </Button> </VerticalStackLayout> </ScrollView> With a Behavior To start the animation when the page loads, add a BeginAnimationBehavior to the element instead: <ScrollView> <VerticalStackLayout> <VerticalStackLayout.Resources> <Rock:FadeToAnimation x:Key="FadeOut" Target="{x:Reference myLabel}" Duration="2000" Opacity="0" /> </VerticalStackLayout.Resources> <Label x:Name="myLabel" Text="Hello Rock!"> <Label.Behaviors> <Rock:BeginAnimationBehavior Animation="{StaticResource FadeOut}" /> </Label.Behaviors> </Label> </VerticalStackLayout> </ScrollView> A behavior starts when its element is attached to its parent, which can happen before the page is fully visible. To cover that gap, the animation waits 250 milliseconds before it begins. Stopping Animations Stop a running animation with an EndAnimation trigger. Here, one button starts the fade and the other stops it: <ScrollView> <VerticalStackLayout> <VerticalStackLayout.Resources> <Rock:FadeToAnimation x:Key="FadeOut" Target="{x:Reference myLabel}" Duration="2000" Opacity="0" /> </VerticalStackLayout.Resources> <Label x:Name="myLabel" Text="Hello Rock!" /> <Button Text="Start Fade"> <Button.Triggers> <EventTrigger Event="Clicked"> <Rock:BeginAnimation Animation="{StaticResource FadeOut}" /> </EventTrigger> </Button.Triggers> </Button> <Button Text="Stop Fade"> <Button.Triggers> <EventTrigger Event="Clicked"> <Rock:EndAnimation Animation="{StaticResource FadeOut}" /> </EventTrigger> </Button.Triggers> </Button> </VerticalStackLayout> </ScrollView> An EndAnimationBehavior also exists, but because behaviors run when the element loads, it’s rarely useful. Triggered Animations Triggered animations stay idle until something starts them, such as a tap on a button or a behavior when the page loads. BackgroundColorAnimation changes an element’s background color.BounceInAnimation bounces an element into view.BounceOutAnimation bounces an element out of view.ColorAnimation animates any color property.CornerRadiusAnimation animates a corner radius.DoubleAnimation animates any number property.FadeInAnimation fades and slides an element into view.FadeOutAnimation fades and slides an element out of view.FadeToAnimation fades an element to a set opacity.FlipAnimation flips an element into view like a card.GroupAnimation starts several animations together.HeartAnimation pulses an element like a heartbeat.IntAnimation animates any whole-number property.JumpAnimation makes an element jump up and down.RelRotateToAnimation rotates an element by a number of degrees.RelScaleToAnimation scales an element by a relative amount.RotateToAnimation rotates an element to a set angle.RotateXToAnimation tilts an element on its x-axis.RotateYToAnimation turns an element on its y-axis.ScaleToAnimation scales an element to a set size.ShakeAnimation shakes an element side to side.ThicknessAnimation animates a margin or padding.TranslateToAnimation moves an element from its normal position.TurnstileInAnimation swings an element into view.TurnstileOutAnimation swings an element out of view. Passive Animations Passive animations are always active. They track a value and update the element whenever that value changes. For example, a color can blend from one value to another as someone drags a slider. AnimateProgressColor changes a color as a tracked value moves.AnimateProgressCornerRadius changes a corner radius as a tracked value moves.AnimateProgressDouble changes a number as a tracked value moves.AnimateProgressInt changes a whole number as a tracked value moves.AnimateProgressThickness changes a margin or padding as a tracked value moves.