* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.0 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | ||
|---|---|---|---|---|---|
| How to: Animate an Object by Using Key Frames | 03/30/2017 |
|
b1f15ba9-cac7-4cea-8699-5c6b55c05c5e |
How to: Animate an Object by Using Key Frames
This example shows how to animate an object, which in this example is the xref:System.Windows.Controls.Page.Background%2A property of a xref:System.Windows.Controls.Page control, by using key frames.
Example
The following example uses the xref:System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames class to animate color changes for the xref:System.Windows.Controls.Page.Background%2A property of a xref:System.Windows.Controls.Page control. The example animation changes to a different background brush at regular intervals. This animation uses the xref:System.Windows.Media.Animation.DiscreteObjectKeyFrame class to create three different key frames. The animation uses key frames in the following manner:
-
At the end of the first second, animates an instance of the xref:System.Windows.Media.LinearGradientBrush class. This section of the example applies a linear gradient to the background color so that the color transitions from yellow to orange to red.
-
At the end of the next second, animates an instance of the xref:System.Windows.Media.RadialGradientBrush class. This section of the example applies a radial gradient to the background color so that the color transitions from white to blue to black.
-
At the end of the third second, animates an instance of the xref:System.Windows.Media.DrawingBrush class. This section of the example applies a checkerboard pattern to the background.
-
The animation begins again and repeats indefinitely.
Note
xref:System.Windows.Media.Animation.DiscreteObjectKeyFrame is the only type of key frame that you can use with the xref:System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames class. Key frames like xref:System.Windows.Media.Animation.DiscreteObjectKeyFrame create sudden changes in values, that is, the color changes in this example occur suddenly.
[!code-xamlkeyframes_snip#ObjectAnimationUsingKeyFramesWholePage]
For the complete sample, see KeyFrame Animation Sample.
See also
- xref:System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames
- xref:System.Windows.Controls.Page.Background%2A
- xref:System.Windows.Controls.Page
- xref:System.Windows.Media.Animation.DiscreteObjectKeyFrame
- xref:System.Windows.Media.LinearGradientBrush
- xref:System.Windows.Media.RadialGradientBrush
- xref:System.Windows.Media.DrawingBrush
- Key-Frame Animations Overview
- Key-Frame How-to Topics