Creating custom animations
The three types of animations provided by WPF (property, path, and key frame) are declarative in nature, which is in large part what makes them easy to use. There's no need to handle timers, change positions manually, or anything like that.
Occasionally, dynamic changes are required which cannot be represented using the built-in animations. Examples include movements that use complex formulas and changes based on user interaction. In such scenarios, it's possible to perform the changes manually with some help from WPF.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a bouncing ball application that uses complex movements and optional user interaction to control the ball:
Create a new WPF application named
CH09.CustomAnimation
.Add a new class named
Ball
. Add using statements to theSystem.ComponentModel
andSystem.Windows
namespaces.Implement the
INotifyPropertyChanged
interface with the event declaration and a simpleOnPropertyChanged...