English
Summary
Conclusions
WPF keeps a tree of visual objects and redraws it itself, so animation comes down to changing dependency properties over time. The basic DoubleAnimation, ColorAnimation, ThicknessAnimation, and PointAnimation animations move between the From, To, and By values over a Duration; the BeginTime, AutoReverse, RepeatBehavior, SpeedRatio, and FillBehavior parameters control timing. A Storyboard combines animations and specifies their targets; it is started by triggers in XAML or with the Begin, Pause, Resume, and Stop methods in code. Easing functions and keyframes make motion natural, RenderTransform transformations let you move, rotate, and scale elements without recalculating the layout, and the CompositionTarget.Rendering event provides frame-by-frame animation for games and physical models. For multimedia, WPF has Image and BitmapImage, SoundPlayer for WAV, MediaPlayer for sound without an interface, and MediaElement for video with control in Manual mode; media files are copied to the program folder as Content.
Self-check questions
- How does the WPF retained graphics mode differ from the GDI+ immediate mode?
- What shapes does WPF have? How do you write a path in the
Path.Datamini-language? - What kinds of transformations does WPF have? What is
RenderTransformOriginfor? - How does
RenderTransformdiffer fromLayoutTransform? Which is better to animate, and why? - What conditions must a property meet to be animatable?
- How does an animation behave if only
To, onlyBy, or no value at all is set? - What do
Duration,BeginTime,AutoReverse,RepeatBehavior, andSpeedRatiomean? - Why might assigning a property in code have no effect after an animation? How do you fix it?
- What is a
Storyboard? How do you write theTargetPropertyfor the angle of aRotateTransform? - How do you start a storyboard with an event in XAML and with a property trigger in a style?
- How do you control a storyboard from code? What is the
isControllableparameter for? - What are easing functions? How do the
EaseIn,EaseOut, andEaseInOutmodes differ? - What kinds of keyframes are there? When are discrete frames needed?
- How does the
CompositionTarget.Renderingevent work? Why is the displacement calculated from the frame time? - What techniques improve animation performance? What does
Freeze()give? - How do
SoundPlayer,MediaPlayer, andMediaElementdiffer? - How do you set up a media file in a project, and why can't it be added as a resource?
Useful links
- WPF graphics and multimedia: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/
- Animation overview: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/animation-overview
- Storyboards: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/storyboards-overview
- Easing functions: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/easing-functions
- Key-frame animation: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/key-frame-animations-overview
- Transforms: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/transforms-overview
- Shapes and drawing: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/shapes-and-basic-drawing-in-wpf-overview
- Frame-by-frame animation with
CompositionTarget: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/how-to-render-on-a-per-frame-interval-using-compositiontarget Freezableobjects: https://learn.microsoft.com/dotnet/desktop/wpf/advanced/freezable-objects-overview- Multimedia in WPF: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/multimedia-overview
- Controlling a
MediaElement: https://learn.microsoft.com/dotnet/desktop/wpf/graphics-multimedia/how-to-control-a-mediaelement-play-pause-stop-volume-and-speed - Blend for Visual Studio: https://learn.microsoft.com/visualstudio/xaml-tools/creating-a-ui-by-using-blend-for-visual-studio