Original link: https://github.com/XamlFlair/XamlFlair
Translation: Desert End Wolf, Linluz (This article is not a full translation, it is recommended to read the original text for more details)

XamlFlair
The goal of the XamlFlair library is to simplify the implementation of common animations and allow developers to easily add single or combined animation sets using a few lines of Xaml.

Showcase
Sekuence Puzzle Game|
:-------------------------------------------:
|
Support the Author
If you'd like to support my work with a coffee, you can do so here: Buy Me a Coffee. Your support motivates me to continue spending time on this project and to keep maintaining and updating it with new features. Thanks in advance!
Table of Contents
- Install from NuGet
- Features Overview
- Basic Concepts
- Usage
- Base Animation Types
- Color Animations (WPF and Uno Only)
- Overriding the Global Default Values
- Using a ResourceDictionary for Base Settings
- Default Animations (WPF Only)
- TransformOn Property (WPF Only)
- Perspective Rotations (UWP Only)
- Combining Animations
- Overriding Values
- Relative Translations on X and Y Axes
- Compound Animations
- Repeating Animations
- Events and Bindings
- Primary and Secondary Completion Commands
- Using the StartWith Property
- Using the AllowOpacityReset Property (WPF Only)
- Using the ClipToBounds Property (UWP and Uno Only)
- Debugging Animations
- Logging Animations
- ListViewBase (UWP and Uno) and ListBox-based (WPF) Animations
Install from NuGet
| Platform | Package | NuGet |
|---|---|---|
| UWP | XamlFlair.UWP | |
| WPF | XamlFlair.WPF | |
| Uno | XamlFlair.Uno |
Use the following command to download XamlFlair from the Package Manager Console:
UWP:
Install-Package XamlFlair.UWP
Your application must target Windows 10 version 1809 (build 17763) or higher.
WPF:
Install-Package XamlFlair.WPF
Uno:
Install-Package XamlFlair.Uno
Your UWP application must target at least Windows 10 version 1809 (build 18362).
Features Overview
| Feature | UWP | WPF | UWP (Uno) | iOS (Uno) | Android (Uno) | Wasm (Uno) Experimental |
|---|---|---|---|---|---|---|
| Animation System | Composition | Storyboard | Storyboard | Storyboard | Storyboard | Storyboard |
| Transform Type | N/A | TransformGroup | CompositeTransform | CompositeTransform | CompositeTransform | CompositeTransform |
| DefaultAnimations.xaml | - | ✔ | - | - | - | - |
TransformOn |
- | ✔ | - | - | - | - |
| Compound Animations | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Relative Translations | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Repeating Animations | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Events & Bindings | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Primary/Secondary Completion Commands | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
StartWith |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
AllowOpacityReset |
- | ✔ | - | - | - | - |
ClipToBounds |
✔ | N/A | ✔ | ✔ | ✔ | ✔ |
| Animated Lists | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Blur Effect | ✔ | ✔ | - | - | - | - |
| Saturation Effect | ✔ | - | - | - | - | - |
| Tint Effect | ✔ | - | - | - | - | - |
| Color Animations | - | ✔ | ✔ | ✔ | ✔ | ✔ |
| Perspective Rotations (Swivel) | ✔ | - | - | - | - | - |
| Debugging Animations | ✔ | ✔ | ✔ | ✔ | ✔ | - |
Basic Concepts
The basic concept of XamlFlair is based on From and To animations. Any UI element composed of From animations will start with one or more arbitrary values and complete using the default values of the corresponding properties. Any UI element composed of To animations will start from its current state and be set to one or more arbitrary values.
Example of a From animation (a UI element moving to Translation(0)):

Example of a To animation (a UI element sliding out from its current state):

Note: It is important to note that there is an exception to this rule for color animations, which is explained in the "Base Animation Types" section.
Usage
First, add the following XAML namespace reference:
UWP and Uno:
xmlns:xf="using:XamlFlair"
WPF:
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
Add the attached property to any FrameworkElement that needs animation:
<Border xf:Animations.Primary="{StaticResource FadeIn}" />
Note: If the
FrameworkElementhas aCompositeTransformdefined in XAML, it will be changed during the animation.
Note: The use of
StaticResourcerefers to a globally common animation, which will be discussed in the next section.
Base Animation Types
Fade

Warning: Be careful when setting
FadeToanimations, because if theVisibilityisVisible, the element will remain in the visual tree. In some cases, you may need to manageIsHitTestVisiblemanually to allow users to click the element.
Translate

Scale

Rotate

Blur (UWP and WPF only)

Saturate (UWP only)

Tint (UWP only)

Color (WPF and Uno only)

Note: It is important to note that when using
Fromanimations for color animations, the color will be set from the specified value to its current state, not the default value.
Swivel (UWP only)

Note: Please read the Perspective Rotations (UWP Only) section for more details.
Below is a list of some notable default values when using XamlFlair:
- Kind: FadeTo
- Duration (milliseconds): 500
- Easing: Cubic
- Easing Mode: EaseOut
- TransformCenterPoint: (0.5, 0.5)
- Event: Loaded
- InterElementDelay (milliseconds): 25 (List controls only)
- TransformOn: Render (WPF only)
- Saturation: 0.5 (UWP only)
- Tint: Transparent (UWP only)
Color Animations (WPF and Uno Only)
When using color animations, it is important to note that they are slightly different from other base animation types. When using ColorTo and ColorFrom, the following must be done:
- Only the following properties can be animated:
Control.Background,Control.Foreground,Control.BorderBrush,Border.Background,Border.BorderBrush,TextBlock.Foreground,Shape.Fill,Shape.Stroke - Ensure a brush is set on the corresponding property to be animated
- The target property must also be specified using
ColorOn
The following example will animate the Fill property of a Rectangle from RoyalBlue to DarkGreen:
<xf:AnimationSettings
x:Key="SampleColorAnimation"
Kind="ColorTo"
Color="DarkGreen"
ColorOn="Fill"
/>
<Rectangle
Fill="RoyalBlue"
xf:Animations.Primary="{StaticResource SampleColorAnimation}"
/>
Overriding the Global Default Values
If you need to globally change one of the default animation values (for example, change the default Duration to 750 instead of 500), you can call the OverrideDefaultSettings function in your application's initialization code. The following example changes the default values for Duration and Easing:
XamlFlair.Animations.OverrideDefaultSettings(
duration: 750,
easing: EasingType.Quadratic);
Thus, in the example code above, every animation will run for 750ms with a quadratic easing.
Using a ResourceDictionary for Base Settings
All common animations should be placed in a global ResourceDictionary (e.g., Animations.xaml) and referenced in the application when needed. The goal is to consolidate all animations into a single file with meaningful names so that any developer can understand exactly what animation will be applied to the FrameworkElement. Here's a small example:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xf="using:XamlFlair"
>
<x:Double x:Key="PositiveOffset">50</x:Double>
<x:Double x:Key="NegativeOffset">-50</x:Double>
<x:Double x:Key="SmallScaleFactor">0.75</x:Double>
<x:Double x:Key="LargeScaleFactor">1.25</x:Double>
<xf:AnimationSettings x:Key="FadeIn" Kind="FadeFrom" Opacity="0" />
<xf:AnimationSettings x:Key="FadeOut" Kind="FadeTo" Opacity="0" />
<!-- Scale to a larger value -->
<xf:AnimationSettings
x:Key="Expand"
Kind="ScaleXTo,ScaleYTo"
ScaleX="{StaticResource LargeScaleFactor}"
ScaleY="{StaticResource LargeScaleFactor}"
/>
<!-- Scale from a larger value -->
<xf:AnimationSettings
x:Key="Contract"
Kind="ScaleXFrom,ScaleYFrom"
ScaleX="{StaticResource LargeScaleFactor}"
ScaleY="{StaticResource LargeScaleFactor}"
/>
. . .
</ResourceDictionary>
To use this pre-configured set of AnimationSettings in your application, follow these steps:
- Right-click on your project in Solution Explorer, then click Add > New Item...
- Select Resource Dictionary and name it
Animations.xaml - Add the following to
App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
- In
Animations.xaml, copy and paste the content from the appropriate link below:
Your application now has a set of common animations ready to use.
Default Animations (WPF Only)
In addition to creating a custom ResourceDictionary with AnimationSettings, XamlFlair also provides some default animations.
To reference these default animations in your application, follow these steps in App.xaml:
- Add the
XamlFlair.WPFnamespace at the top:
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
- Update the Application Resources:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<xf:XamlFlairResources />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Your application now has a set of global default animations ready to use.
If Visual Studio IntelliSense is not working when using <xf:XamlFlairResources />, you may need to try the following:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/XamlFlair.WPF;component/DefaultAnimations.xaml"
/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
TransformOn Property (WPF Only)
The RenderTransform can be animated using the TransformOn property. Available options are Render and Layout. When unspecified, it defaults to Render. Here's an example of both options:

Note: It is very important to note that WPF's
LayoutTransformdoes not support anyTranslateTransform, so translate animations will never take effect. You can learn more in the remarks section here.
The original readme.md is too long, and the translation is getting lengthy. If you are interested, please refer to the original text. Finally, here's an image:
