DoubleAnimation. WPF supports animation of elements. To move an element, we can use a canvas and adjust its position within the canvas.
Some elements. We introduce the BeginStoryboard, Storyboard and DoubleAnimation elements. These are used with DoubleAnimation to specify the animation info.
Example. Animation can be implemented with C# code, but in the simplest case this is not necessary. Here I add a Canvas element to the Window.
Program output. The rectangle will creep across the window towards the right. It does this in 2 seconds. You can change the Duration to make it slower or faster.
Info We can adjust the "From" and the "To" to change the animation's start and end values. These are used for the TargetProperty.
Tip Please add the parentheses around the TargetProperty in your XAML. If you do not, an error (a confusing one) will occur.
A discussion. There are other "Animation" elements. Similar to DoubleAnimation, we can employ DecimalAnimation to manipulate a floating-point property. ByteAnimation is similar.
And ColorAnimation can change a color, creating fade effects. These elements can make WPF seem excessively complicated.
A summary. With WPF, we gain a large set of graphical effects. This is a key advantage of WPF. With Storyboards, we can specify the nature of our animations.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.