Animations in XAML

Animations can enhance your app by adding movement and interactivity. Past using the animations from the Windows Runtime animation library, you tin integrate the Windows expect and feel into your app. This topic provides a summary of the animations and examples of typical scenarios where each is used.

Tip

The Windows Runtime controls for XAML include certain types of animations as congenital-in behaviors that come up from an animation library. By using these controls in your app, you lot tin can get the blithe look and feel without having to program it yourself.

Animations from the Windows Runtime animation library provide these benefits:

  • Motions that align to the Guidelines for animations
  • Fast, fluid transitions between UI states that inform but do not distract the user
  • Visual behavior that indicates transitions within an app to the user

For instance, when the user adds an item to a list, instead of the new item instantly appearing in the list, the new item animates into identify. The other items in the list animate to their new positions over a brusque menstruum of time, making room for the added item. The transition beliefs here makes the control interaction more apparent to the user.

Windows 10, version 1607 introduces a new ConnectedAnimationService API for implementing animations where an element appears to breathing between views during a navigation. This API has a different usage pattern from the other animation library API's. Usage of ConnectedAnimationService is covered in the reference page.

The animation library does not provide animations for every possible scenario. At that place are cases where you might wish to create a custom animation in XAML. For more than info, see Storyboarded animations.

Additionally, for sure advanced scenarios like animating an item based on scroll position of a ScrollViewer, developers may wish to use Visual Layer interoperation to implement custom animations. Come across Visual Layer for more than information.

Types of animations

The Windows Runtime animation system and the animation library serve the larger goal of enabling controls and other parts of UI to have an blithe behavior. There are several distinct types of animations.

  • Theme transitions are applied automatically when sure conditions change in the UI, involving controls or elements from the predefined Windows Runtime XAML UI types. These are termed theme transitions considering the animations back up the Windows look and experience, and define what all apps do for particular UI scenarios when they change from one interaction style to another. The theme transitions are part of the blitheness library.
  • Theme animations are animations to one or more properties of predefined Windows Runtime XAML UI types. Theme animations differ from theme transitions considering theme animations target one specific chemical element and exist in specific visual states within a command, whereas the theme transitions are assigned to backdrop of the control that exist outside of the visual states and influence the transitions between those states. Many of the Windows Runtime XAML controls include theme animations inside storyboards that are function of their control template, with the animations triggered past visual states. So long as you're not modifying the templates, y'all'll have those congenital-in theme animations bachelor for the controls in your UI. However, if you practice supercede templates, then yous'll be removing the built-in control theme animations too. To go them dorsum, you must ascertain a storyboard that includes theme animations within the control'due south ready of visual states. You tin can also run theme animations from storyboards that aren't inside visual states and start them with the Begin method, but that'due south less mutual. Theme animations are part of the animation library.
  • Visual transitions are applied when a command transitions from one of its divers visual states to another land. These are custom animations that you write, and are typically related to the custom template you write for a control and the visual state definitions within that template. The animation merely runs during the fourth dimension between states, and that's typically a short amount of fourth dimension, a few seconds at nearly. For more info, run into "VisualTransition" section of Storyboarded animations for visual states.
  • Storyboarded animations animate the value of a Windows Runtime dependency belongings over time. Storyboards can be divers as part of a visual transition, or triggered at runtime by the application. For more info, see Storyboarded animations. For more info nearly dependency properties and where they exist, run into Dependency properties overview.
  • Connected animations provided by the new ConnectedAnimationService API allow developers to hands create an effect where an element appears to animate between views during a navigation. This API is bachelor starting in Windows 10, version 1607. See ConnectedAnimationService for more information.

Animations available in the library

The following animations are supplied in the animation library. Click on the proper name of an animation to learn more about their primary usage scenarios, how to ascertain them, and to see an case of the animation.

  • Page transition: Animates page transitions in a Frame.
  • Content and archway transition: Animates one piece or gear up of content into or out of view.
  • Fade in/out, and crossfade: Shows transient elements or controls, or refreshes a content surface area.
  • Pointer up/down: Gives visual feedback of a tap or click on a tile.
  • Reposition: Moves an element into a new position.
  • Show/hide popup: Displays contextual UI on top of the view.
  • Testify/hide edge UI: Slides edge-based UI, including big UI such every bit a panel, into or out of view.
  • Listing item changes: Adds or deletes an item from a list, or reordering of the items.
  • Elevate/drop: Gives visual feedback during a drag-and-drop operation.

Page transition

Use page transitions to animate navigation within an app. Since most all apps use some kind of navigation, page transition animations are the most common type of theme animation used by apps. See NavigationThemeTransition for more information about the folio transition APIs.

Content transition and entrance transition

Use content transition animations (ContentThemeTransition) to move a piece or a fix of content into or out of the current view. For example, the content transition animations show content that was not set to display when the folio was kickoff loaded, or when the content changes on a section of a page.

EntranceThemeTransition represents a motion that can apply to content when a page or large department of UI is first loaded. Thus the first advent of content tin can offer unlike feedback than a modify to content does. EntranceThemeTransition is equivalent to a NavigationThemeTransition with the default parameters, but may be used outside of a Frame.

Fade in/out, and crossfade

Use fade in and fade out animations to show or hide transient UI or controls. In XAML these are represented as FadeInThemeAnimation and FadeOutThemeAnimation. I instance is in an app bar in which new controls can appear due to user interaction. Another example is a transient scroll bar or panning indicator that is faded out afterwards no user input has been detected for some corporeality of time. Apps should also utilise the fade in blitheness when they transition from a placeholder item to the terminal item as content loads dynamically.

Employ a crossfade animation to smoothen the transition when an item's country is changing; for instance, when the app refreshes the current contents of a view. The XAML animation library does non supply a dedicated crossfade animation (no equivalent for crossFade), but you can accomplish the same event using FadeInThemeAnimation and FadeOutThemeAnimation with overlapped timing.

Pointer up/down

Use the PointerUpThemeAnimation and PointerDownThemeAnimation animations to requite the user feedback for a successful tap or click on a tile. For example, when a user clicks or taps down on a tile, the pointer down animation is played. One time the click or tap has been released, the pointer up animation is played.

Reposition

Use the reposition animations (RepositionThemeAnimation or RepositionThemeTransition) to motion an chemical element into a new position. For case, moving the headers in an items control uses the reposition animation.

Prove/hide popup

Use the PopInThemeAnimation and PopOutThemeAnimation when you show and hide a Popup or like contextual UI on top of the electric current view. PopupThemeTransition is a theme transition that'southward useful feedback if you want to light dismiss a popup.

Show/hide edge UI

Use the EdgeUIThemeTransition animation to slide small-scale, edge-based UI into and out of view. For example, use these animations when you evidence a custom app bar at the meridian or bottom of the screen or a UI surface for errors and warnings at the tiptop of the screen.

Employ the PaneThemeTransition animation to show and hide a pane or panel. This is for large border-based UI such equally a custom keyboard or a task pane.

List item changes

Use the AddDeleteThemeTransition animation to add together animated behavior when you add or delete an item in an existing list. For add, the transition will first reposition existing items in the listing to make space for the new items, so add the new items. For delete, the transition removes items from a listing and, if necessary, repositions the remaining list items once the deleted items take been removed.

There's likewise a separate ReorderThemeTransition that you lot apply if an detail changes position in a list. This is blithe differently than deleting an item and adding it in a new place with the associated delete/add animations.

Note that these animations are included in the default ListView and GridView templates and then you exercise not need to manually add these animations if yous are already using these controls.

Drag/driblet

Use the elevate animations (DragItemThemeAnimation, DragOverThemeAnimation) and drop blitheness (DropTargetItemThemeAnimation) to requite visual feedback when the user drags or drops an detail.

When agile, the animations show the user that the list can be rearranged around a dropped item. It is helpful for users to know where the particular will exist placed in a list if it is dropped at the current location. The animations requite visual feedback that an item being dragged can be dropped between 2 other items in the list and that those items will motion out of the way.

Using animations with custom controls

The following table summarizes our recommendations for which animation you should use when you create a custom version of these Windows Runtime controls:

UI type Recommended animation
Dialog box FadeInThemeAnimation and FadeOutThemeAnimation
Flyout PopInThemeAnimation and PopOutThemeAnimation
Tooltip FadeInThemeAnimation and FadeOutThemeAnimation
Context carte PopInThemeAnimation and PopOutThemeAnimation
Command bar EdgeUIThemeTransition
Task pane or border-based console PaneThemeTransition
Contents of any UI container ContentThemeTransition
For controls or if no other animation applies FadeInThemeAnimation and FadeOutThemeAnimation

Transition animation examples

Ideally, your app uses animations to heighten the user interface or to make it more attractive without annoying your users. One way you can do this is to utilize animated transitions to UI so that when something enters or leaves the screen or otherwise changes, the blitheness draws the attention of the user to the change. For example, your buttons may rapidly fade in and out of view rather than just appear and disappear. We created a number of APIs that can be used to create recommended or typical animation transitions that are consistent. The case hither shows how to use an animation to a button then that it swiftly slides into view.

                        <Button Content="Transitioning Push">      <Push.Transitions>          <TransitionCollection>               <EntranceThemeTransition/>          </TransitionCollection>      </Button.Transitions>  </Button>                                              

In this code, we add together the EntranceThemeTransition object to the transition collection of the button. Now, when the button is first rendered, it swiftly slides into view rather than only announced. You can prepare a few backdrop on the blitheness object in order to adjust how far it slides and from what management, but it's really meant to be a simple API for a specific scenario, that is, to make an middle-catching archway.

You tin can also ascertain transition blitheness themes in the style resources of your app, allowing you to utilize the effect uniformly. This example is equivalent to the previous one, only it is applied using a Mode:

                        <UserControl.Resource>      <Way ten:Fundamental="DefaultButtonStyle" TargetType="Button">          <Setter Property="Transitions">              <Setter.Value>                  <TransitionCollection>                      <EntranceThemeTransition/>                  </TransitionCollection>              </Setter.Value>         </Setter>     </Style> </UserControl.Resources>        <StackPanel x:Name="LayoutRoot">     <Push Style="{StaticResource DefaultButtonStyle}" Content="Transitioning Push"/> </StackPanel>                                              

The previous examples apply a theme transition to an individual control, however, theme transitions are fifty-fifty more interesting when you use them to a container of objects. When you do this, all the child objects of the container have part in the transition. In the post-obit case, an EntranceThemeTransition is applied to a Filigree of rectangles.

                        <!-- If y'all set an EntranceThemeTransition blitheness on a panel, the      children of the panel will automatically start when they animate      into view to create a visually appealing entrance. -->         <ItemsControl Grid.Row="1" 10:Name="rectangleItems">     <ItemsControl.ItemContainerTransitions>         <TransitionCollection>             <EntranceThemeTransition/>         </TransitionCollection>     </ItemsControl.ItemContainerTransitions>     <ItemsControl.ItemsPanel>         <ItemsPanelTemplate>             <WrapGrid Summit="400"/>         </ItemsPanelTemplate>     </ItemsControl.ItemsPanel>                  <!-- The sequence children announced depends on their guild in           the panel'due south children, not necessarily on where they render          on the screen. Be sure to arrange your child elements in          the club you want them to transition into view. -->     <ItemsControl.Items>         <Rectangle Make full="Crimson" Width="100" Height="100" Margin="x"/>         <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>         <Rectangle Fill="Red" Width="100" Top="100" Margin="10"/>         <Rectangle Fill="Blood-red" Width="100" Summit="100" Margin="10"/>         <Rectangle Fill="Carmine" Width="100" Summit="100" Margin="10"/>         <Rectangle Fill="Red" Width="100" Acme="100" Margin="10"/>         <Rectangle Fill="Reddish" Width="100" Height="100" Margin="10"/>         <Rectangle Make full="Red" Width="100" Height="100" Margin="10"/>         <Rectangle Fill up="Crimson" Width="100" Pinnacle="100" Margin="10"/>     </ItemsControl.Items> </ItemsControl>                                              

The child rectangles of the Grid transition into view 1 afterwards the other in a visually pleasing way rather than all at once every bit would be the instance if y'all applied this animation to the rectangles individually.

Here'southward a demonstration of this animation:

Animation showing child rectangle transitioning into view

Child objects of a container can likewise re-flow when ane or more of those children change position. In the following example, we utilize a RepositionThemeTransition to a grid of rectangles. When you lot remove one of the rectangles, all the other rectangles re-menstruation into their new position.

                        <Button Content="Remove Rectangle" Click="RemoveButton_Click"/>          <ItemsControl Grid.Row="1" 10:Name="rectangleItems">     <ItemsControl.ItemContainerTransitions>         <TransitionCollection>                                  <!-- Without this, there would exist no animation when items                   are removed. -->             <RepositionThemeTransition/>         </TransitionCollection>     </ItemsControl.ItemContainerTransitions>     <ItemsControl.ItemsPanel>         <ItemsPanelTemplate>             <WrapGrid Summit="400"/>         </ItemsPanelTemplate>     </ItemsControl.ItemsPanel>                  <!-- All these rectangles are merely to demonstrate how the items          in the grid re-flow into position when one of the child items          are removed. -->     <ItemsControl.Items>         <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>         <Rectangle Fill="Reddish" Width="100" Height="100" Margin="x"/>         <Rectangle Fill="Cherry" Width="100" Acme="100" Margin="10"/>         <Rectangle Fill="Red" Width="100" Summit="100" Margin="x"/>         <Rectangle Fill up="Red" Width="100" Height="100" Margin="10"/>         <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>         <Rectangle Fill="Reddish" Width="100" Height="100" Margin="10"/>         <Rectangle Fill="Red" Width="100" Height="100" Margin="x"/>         <Rectangle Fill="Carmine" Width="100" Height="100" Margin="10"/>     </ItemsControl.Items> </ItemsControl>                                              
                        private void RemoveButton_Click(object sender, RoutedEventArgs e) {     if (rectangleItems.Items.Count > 0)     {             rectangleItems.Items.RemoveAt(0);     }                          }                                              
                        // .h private: void RemoveButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);  //.cpp void BlankPage::RemoveButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ eastward) {     if (rectangleItems->Items->Size > 0)     {             rectangleItems->Items->RemoveAt(0);     } }                                              

Yous tin can apply multiple transition animations to a single object or object container. For case, if you want the listing of rectangles to animate into view and also animate when they modify position, yous tin can use the RepositionThemeTransition and EntranceThemeTransition like this:

                        ... <ItemsControl.ItemContainerTransitions>     <TransitionCollection>         <EntranceThemeTransition/>                             <RepositionThemeTransition/>     </TransitionCollection> </ItemsControl.ItemContainerTransitions> ...                                              

There are several transition effects to create animations on your UI elements as they are added, removed, reordered, and and so on. The names of these APIs all contain "ThemeTransition":

API Clarification
NavigationThemeTransition Provides a Windows personality animation for folio navigation in a Frame.
AddDeleteThemeTransition Provides the animated transition behavior for when controls add together or delete children or content. Typically the command is an item container.
ContentThemeTransition Provides the animated transition beliefs for when the content of a control is changing. You tin apply this in addition to AddDeleteThemeTransition.
EdgeUIThemeTransition Provides the animated transition behavior for a (small) edge UI transition.
EntranceThemeTransition Provides the animated transition beliefs for when controls outset appear.
PaneThemeTransition Provides the animated transition beliefs for a panel (large edge UI) UI transition.
PopupThemeTransition Provides the animated transition behavior that applies to popular-in components of controls (for example, tooltip-similar UI on an object) as they appear.
ReorderThemeTransition Provides the blithe transition behavior for when listing-view controls items change gild. Typically this happens equally a result of a drag-driblet operation. Different controls and themes can have varying characteristics for the animations.
RepositionThemeTransition Provides the animated transition behavior for when controls alter position.

Theme animation examples

Transition animations are uncomplicated to apply. But you may want to have a fleck more control over the timing and lodge of your blitheness effects. You tin can use theme animations to enable more command while still using a consistent theme for how your blitheness behaves. Theme animations also require less markup than custom animations. Here, nosotros use the FadeOutThemeAnimation to make a rectangle fade out of view.

                        <StackPanel>         <StackPanel.Resources>         <Storyboard x:Name="myStoryboard">             <FadeOutThemeAnimation TargetName="myRectangle" />         </Storyboard>     </StackPanel.Resource>     <Rectangle PointerPressed="Rectangle_Tapped" 10:Name="myRectangle"                 Fill up="Blueish" Width="200" Height="300"/> </StackPanel>                                              
                        // When the user taps the rectangle, the animation begins. private void Rectangle_Tapped(object sender, PointerRoutedEventArgs e) {     myStoryboard.Begin(); }                                              
                        ' When the user taps the rectangle, the animation begins. Private Sub Rectangle_Tapped(sender As Object, e As PointerRoutedEventArgs)     myStoryboard.Begin() Cease Sub                                              
                        //.h void Rectangle_Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);  //.cpp void BlankPage::Rectangle_Tapped(Object^ sender, PointerRoutedEventArgs^ e) {     myStoryboard->Begin(); }                                              

Unlike transition animations, a theme animation doesn't take a built-in trigger (the transition) that runs it automatically. You must utilise a Storyboard to contain a theme animation when you define it in XAML. You can likewise change the default beliefs of the animation. For instance, you can dull down the fade-out by increasing the Elapsing time value on the FadeOutThemeAnimation.

Note  For purposes of showing basic animation techniques, we're using app lawmaking to start the animation past calling methods of Storyboard. You can command how the Storyboard animations run using the Begin, Stop, Interruption, and Resume Storyboard methods. Withal, that's not typically how yous include library animations in apps. Rather, you usually integrate the library animations into the XAML styles and templates practical to controls or elements. Learning about templates and visual states is a little more than involved. Merely nosotros do cover how yous'd use library animations in visual states as part of the Storyboarded animations for visual states topic.

You can apply several other theme animations to your UI elements to create blitheness effects. The names of these API all contain "ThemeAnimation":

API Description
DragItemThemeAnimation Represents the preconfigured animation that applies to item elements being dragged.
DragOverThemeAnimation Represents the preconfigured animation that applies to the elements underneath an element beingness dragged.
DropTargetItemThemeAnimation The preconfigured animation that applies to potential drop target elements.
FadeInThemeAnimation The preconfigured opacity animation that applies to controls when they commencement appear.
FadeOutThemeAnimation The preconfigured opacity blitheness that applies to controls when they are removed from UI or subconscious.
PointerDownThemeAnimation The preconfigured blitheness for user action that taps or clicks an particular or element.
PointerUpThemeAnimation The preconfigured animation for user action that runs after a user taps downwardly on an item or element and the action is released.
PopInThemeAnimation The preconfigured blitheness that applies to pop-in components of controls as they announced. This blitheness combines opacity and translation.
PopOutThemeAnimation The preconfigured animation that applies to pop-in components of controls as they are airtight or removed. This animation combines opacity and translation.
RepositionThemeAnimation The preconfigured animation for an object as it is repositioned.
SplitCloseThemeAnimation The preconfigured animation that conceals a target UI using an animation in the style of a ComboBox opening and closing.
SplitOpenThemeAnimation The preconfigured animation that reveals a target UI using an blitheness in the manner of a ComboBox opening and endmost.
DrillInThemeAnimation Represents a preconfigured blitheness that runs when a user navigates frontward in a logical hierarchy, like from a listing page to a detail page.
DrillOutThemeAnimation Represents a preconfigured animation that runs when a user navigates backward in a logical hierarchy, like from a detail page to a list page.

Create your own animations

When theme animations are not enough for your needs, you tin create your ain animations. You animate objects past animating ane or more than of their belongings values. For example, you lot can breathing the width of a rectangle, the angle of a RotateTransform, or the color value of a push. We term this type of custom animation a storyboarded animation, to distinguish it from the library animations that the Windows Runtime already provides as a preconfigured animation type. For storyboarded animations, you lot use an blitheness that can change values of a item type (for example DoubleAnimation to animate a Double) and put that animation within a Storyboard to control it.

In order to be blithe, the property you are animating must be a dependency property. For more info about dependency backdrop, see Dependency properties overview. For more info on creating custom storyboarded animations, including how to target and control them, run across Storyboarded animations.

The biggest expanse of app UI definition in XAML where you'll define custom storyboarded animations is if you are defining visual states for controls in XAML. You lot'll be doing this either because you lot are creating a new command class, or considering you are re-templating an existing command that has visual states in its control template. For more info, see Storyboarded animations for visual states.