UWP Community toolkit provides several tools to animate your UIElements.
You can use behaviors from within Blend for an editor experience, or you can decide to do it manually using code.
Animation Styles and Documentation
Behaviors are powerful tools for designers that can be defined in Blend:
You can specify to start animation automatically upon loading (with AutomaticallyStart=”True”) or you can use code to do it manually.
Animations using code only
For developers, the toolkit provides extensions for UIElement to match what can be done with behaviors.
So for instance if you want to blur an element, you only need to call this code:
Animations are asynchronous by essence. You can await an animation if you start it with
StartAsync(), but there is also a non-awaitable (but still asynchronous) version if you start it with
You can also chain animations thanks to the toolkit fluid API:
In this case the toolkit will trigger a rotation, a fade and a blur simultaneously.
If you want to start animations in a serial way, you can use
Every animation can have its own duration but there is a way to set it up for all animations at once:
As animations are awaitable, it is easy to execute code after animations are completed. If you do not want to await your animations, you can then use the Completed event:
And if you want to stop an animation before it ends, jsut call
How does it work under the hood?
Animations can be done using XAML storyboards or Windows Composition. By default the toolkit will use XAML storyboards unless you set AnimationSet.UseComposition = true.
Using Windows Composition
While Windows Composition is faster and more efficient than XAML storyboards, it is important to understand several drawbacks that you may face when using it.
If you are using SDK 10586, Windows Composition and XAML storyboards behave exactly in the same way.
If you are using SDK 14393, the interoperabilty between XAML and Windows Composition changed (as stated by this article). In a nutshell, animating Offset and opacity with Windows Composition is only recommended if you do not change these states on XAML side. If you want to use Windows Composition and animate offset, then the safest way is to use a layout in XAML which positions the element at 0,0. same for opacity where it is recommended to not define it in XAML.
Offset, Scale and Rotate
When using storyboards for offset, scale and rotate, the toolkit will generate a CompositeTransform for you and will merge it with the current UIElement.RenderTransform (using a TransformGroup). This means that you do not have to worry about the current state of your UIElement because the toolkit will take care of keeping it unchanged.
Read the getting Started with the UWP Community Toolkit for instructions on using these API functions in your own projects.
Windows 10 Store App
Want to see the controls and animations in action before jumping into the code? We have published the UWP Community Toolkit Sample App to the Windows 10 store. Download the app and play with the controls live to see what they do before ever writing a line of code.
Visit the UWP Community Toolkit Github Repository to see the current source code, what is coming next, and to clone the repository. Community contributions are welcome!