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 pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.