Skip to main content
.NET Framework Class Library
ColorAnimationUsingKeyFrames Class

Animates the value of a Color property along a set of KeyFrames over a specified Duration.

Namespace:   System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax
<[%$TOPIC/ms613802_en-us_VS_110_5_0_0_0_0%]("KeyFrames")> _
Public Class ColorAnimationUsingKeyFrames _
	Inherits [%$TOPIC/ms613802_en-us_VS_110_5_0_0_0_1%] _
	Implements [%$TOPIC/ms613802_en-us_VS_110_5_0_0_0_2%], [%$TOPIC/ms613802_en-us_VS_110_5_0_0_0_3%]
[[%$TOPIC/ms613802_en-us_VS_110_5_0_1_0_0%]("KeyFrames")]
public class ColorAnimationUsingKeyFrames : [%$TOPIC/ms613802_en-us_VS_110_5_0_1_0_1%], 
	[%$TOPIC/ms613802_en-us_VS_110_5_0_1_0_2%], [%$TOPIC/ms613802_en-us_VS_110_5_0_1_0_3%]
[[%$TOPIC/ms613802_en-us_VS_110_5_0_2_0_0%](L"KeyFrames")]
public ref class ColorAnimationUsingKeyFrames : public [%$TOPIC/ms613802_en-us_VS_110_5_0_2_0_1%], 
	[%$TOPIC/ms613802_en-us_VS_110_5_0_2_0_2%], [%$TOPIC/ms613802_en-us_VS_110_5_0_2_0_3%]
[<[%$TOPIC/ms613802_en-us_VS_110_5_0_3_0_0%]("KeyFrames")>]
type ColorAnimationUsingKeyFrames =  
    class 
        inherit [%$TOPIC/ms613802_en-us_VS_110_5_0_3_0_1%] 
        interface [%$TOPIC/ms613802_en-us_VS_110_5_0_3_0_2%] 
        interface [%$TOPIC/ms613802_en-us_VS_110_5_0_3_0_3%] 
    end
<ColorAnimationUsingKeyFrames>
  [%$TOPIC/ms613802_en-us_VS_110_5_0_4_0_0%]
</ColorAnimationUsingKeyFrames>

The ColorAnimationUsingKeyFrames type exposes the following members.

Constructors
  NameDescription
Public method ColorAnimationUsingKeyFramesInitializes a new instance of the ColorAnimationUsingKeyFrames class.
Top
Properties
  NameDescription
Public property AccelerationRatioGets or sets a value specifying the percentage of the timeline's Duration spent accelerating the passage of time from zero to its maximum rate. (Inherited from Timeline.)
Public property AutoReverseGets or sets a value that indicates whether the timeline plays in reverse after it completes a forward iteration. (Inherited from Timeline.)
Public property BeginTimeGets or sets the time at which this Timeline should begin. (Inherited from Timeline.)
Public property CanFreezeGets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.)
Public property DecelerationRatioGets or sets a value specifying the percentage of the timeline's Duration spent decelerating the passage of time from its maximum rate to zero. (Inherited from Timeline.)
Public property DependencyObjectTypeGets the DependencyObjectType that wraps the CLR type of this instance.  (Inherited from DependencyObject.)
Public property DispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public property DurationGets or sets the length of time for which this timeline plays, not counting repetitions. (Inherited from Timeline.)
Public property FillBehaviorGets or sets a value that specifies how the Timeline behaves after it reaches the end of its active period. (Inherited from Timeline.)
Public property HasAnimatedPropertiesGets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties. (Inherited from Animatable.)
Public property IsAdditiveGets a value that specifies whether the animation's output value is added to the base value of the property being animated.
Public property IsCumulativeGets or sets a value that specifies whether the animation's value accumulates when it repeats.
Public property IsDestinationDefaultGets a value that indicates whether this animation uses the defaultDestinationValue parameter of the GetCurrentValue method as its destination value. (Inherited from AnimationTimeline.)
Public property IsFrozenGets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.)
Public property IsSealedGets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.)
Public property KeyFrames Gets or sets the collection of ColorKeyFrame objects that define the animation.
Public property Name Gets or sets the name of this Timeline. (Inherited from Timeline.)
Public property RepeatBehaviorGets or sets the repeating behavior of this timeline. (Inherited from Timeline.)
Public property SpeedRatioGets or sets the rate, relative to its parent, at which time progresses for this Timeline. (Inherited from Timeline.)
Public property TargetPropertyTypeGets the type of value this animation generates. (Inherited from ColorAnimationBase.)
Top
Methods
  NameDescription
Protected method AddChildAdds a child ColorKeyFrame to this ColorAnimationUsingKeyFrames.
Protected method AddTextAdds a text string as a child of this ColorAnimationUsingKeyFrames.
Protected method AllocateClockCreates a Clock for this AnimationTimeline. (Inherited from AnimationTimeline.)
Public method ApplyAnimationClock(DependencyProperty, AnimationClock)Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.)
Public method ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.)
Public method BeginAnimation(DependencyProperty, AnimationTimeline)Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.)
Public method BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.)
Public method CheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public method ClearValue(DependencyProperty)Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)
Public method ClearValue(DependencyPropertyKey)Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)
Public method CloneCreates a modifiable clone of this ColorAnimationUsingKeyFrames, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values.
Protected method CloneCoreMakes this instance a deep copy of the specified ColorAnimationUsingKeyFrames. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values. (Overrides FreezableCloneCore(Freezable).)
Public method CloneCurrentValueCreates a modifiable clone of this ColorAnimationUsingKeyFrames object, making deep copies of this object's current values. Resource references, data bindings, and animations are not copied, but their current values are.
Protected method CloneCurrentValueCoreMakes this instance a modifiable deep copy of the specified ColorAnimationUsingKeyFrames using current property values. Resource references, data bindings, and animations are not copied, but their current values are. (Overrides FreezableCloneCurrentValueCore(Freezable).)
Public method CoerceValueCoerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.)
Public method CreateClockCreates a new AnimationClock from this AnimationTimeline. (Inherited from AnimationTimeline.)
Public method CreateClock(Boolean)Creates a new Clock from this Timeline and specifies whether the new Clock is controllable. If this Timeline has children, a tree of clocks is created with this Timeline as the root. (Inherited from Timeline.)
Protected method CreateInstanceInitializes a new instance of the Freezable class. (Inherited from Freezable.)
Protected method CreateInstanceCoreCreates a new instance of ColorAnimationUsingKeyFrames. (Overrides FreezableCreateInstanceCore.)
Public method EqualsDetermines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method FreezeMakes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.)
Protected method FreezeCoreMakes this instance of ColorAnimationUsingKeyFrames object unmodifiable or determines whether it can be made unmodifiable. (Overrides TimelineFreezeCore(Boolean).)
Public method GetAnimationBaseValueReturns the non-animated value of the specified DependencyProperty. (Inherited from Animatable.)
Public method GetAsFrozenCreates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.)
Protected method GetAsFrozenCoreMakes this instance a clone of the specified ColorAnimationUsingKeyFrames object. (Overrides TimelineGetAsFrozenCore(Freezable).)
Public method GetCurrentValue(Color, Color, AnimationClock)Gets the current value of the animation. (Inherited from ColorAnimationBase.)
Public method GetCurrentValue(Object, Object, AnimationClock)Gets the current value of the animation. (Inherited from ColorAnimationBase.)
Public method GetCurrentValueAsFrozenCreates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.)
Protected method GetCurrentValueAsFrozenCoreMakes this instance a frozen clone of the specified ColorAnimationUsingKeyFrames. Resource references, data bindings, and animations are not copied, but their current values are. (Overrides TimelineGetCurrentValueAsFrozenCore(Freezable).)
Protected method GetCurrentValueCore Calculates a value that represents the current value of the property being animated, as determined by this instance of ColorAnimationUsingKeyFrames. (Overrides ColorAnimationBaseGetCurrentValueCore(Color, Color, AnimationClock).)
Public method GetHashCodeGets a hash code for this DependencyObject. (Inherited from DependencyObject.)
Public method GetLocalValueEnumeratorCreates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)
Protected method GetNaturalDurationReturns the length of a single iteration of this Timeline. (Inherited from Timeline.)
Protected method GetNaturalDurationCoreProvide a custom natural Duration when the Duration property is set to Automatic. (Overrides AnimationTimelineGetNaturalDurationCore(Clock).)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method GetValueReturns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)
Public method InvalidatePropertyRe-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnChangedCalled when the current ColorAnimationUsingKeyFrames object is modified. (Overrides FreezableOnChanged.)
Protected method OnFreezablePropertyChanged(DependencyObject, DependencyObject)Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set. (Inherited from Freezable.)
Protected method OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. (Inherited from Freezable.)
Protected method OnPropertyChangedOverrides the DependencyObject implementation of OnPropertyChanged to also invoke any Changed handlers in response to a changing dependency property of type Freezable. (Inherited from Freezable.)
Public method ReadLocalValueReturns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)
Protected method ReadPreambleEnsures that the Freezable is being accessed from a valid thread. Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties. (Inherited from Freezable.)
Public method SetCurrentValueSets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)
Public method SetValue(DependencyProperty, Object)Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)
Public method SetValue(DependencyPropertyKey, Object)Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)
Public method ShouldSerializeKeyFramesReturns true if the value of the KeyFrames property of this instance of ColorAnimationUsingKeyFrames should be value-serialized.
Protected method ShouldSerializePropertyReturns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Public method VerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Protected method WritePostscriptRaises the Changed event for the Freezable and invokes its OnChanged method. Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties. (Inherited from Freezable.)
Protected method WritePreambleVerifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties. (Inherited from Freezable.)
Top
Events
  NameDescription
Public event ChangedOccurs when the Freezable or an object it contains is modified. (Inherited from Freezable.)
Public event CompletedOccurs when this timeline has completely finished playing: it will no longer enter its active period. (Inherited from Timeline.)
Public event CurrentGlobalSpeedInvalidatedOccurs when the rate at which time progresses for the timeline's clock changes. (Inherited from Timeline.)
Public event CurrentStateInvalidatedOccurs when the CurrentState property of the timeline's Clock is updated. (Inherited from Timeline.)
Public event CurrentTimeInvalidatedOccurs when the CurrentTime property of the timeline's Clock is updated. (Inherited from Timeline.)
Public event RemoveRequestedOccurs when the clock created for this timeline or one of its parent timelines is removed. (Inherited from Timeline.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method IAddChildAddChildAdds a child object.
Explicit interface implemetation Private method IAddChildAddTextAdds the text content of a node to the object.
Explicit interface implemetation Private property IKeyFrameAnimationKeyFramesGets or sets an ordered collection P:System.Windows.Media.Animation.IKeyFrameAnimation.KeyFrames associated with this animation sequence.
Top
Remarks

A key frame animation's target values are defined by its KeyFrames property, which contains a collection of ColorKeyFrame objects. Each ColorKeyFrame defines a segment of the animation with its own target Value and KeyTime. When the animation runs, it progresses from one key value to the next at the specified key times.

There are three types of ColorKeyFrame classes, one for each supported interpolation method: LinearColorKeyFrame, DiscreteColorKeyFrame, and SplineColorKeyFrame.

Unlike a ColorAnimation, a ColorAnimationUsingKeyFrames can have more than two of target values. You can also control the interpolation method of individual ColorKeyFrame segments.

Examples

This example shows how to animate the Color of a SolidColorBrush by using key frames.

The following example uses the ColorAnimationUsingKeyFrames class to animate the Color property of a SolidColorBrush. This animation uses three key frames in the following manner:

  1. During the first two seconds, uses an instance of the LinearColorKeyFrame class to gradually change the color from green to red. Linear key frames like LinearColorKeyFrame create a smooth linear transition between values.

  2. During the end of the next half second, uses an instance of the DiscreteColorKeyFrame class to quickly change the color from red to yellow. Discrete key frames like DiscreteColorKeyFrame create sudden changes between values, that is, the color change in this part of the animation occurs quickly and is not subtle.

  3. During the final two seconds, uses an instance of the SplineColorKeyFrame class to change the color again—this time from yellow back to green. Spline key frames like SplineColorKeyFrame create a variable transition between values according to the values of the KeySpline property. In this example, the change in color begins slowly and speeds up exponentially toward the end of the time segment.


Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Shapes
Imports System.Windows.Media.Animation
Imports System.Windows.Media

Namespace Microsoft.Samples.KeyFrameExamples
	Public Class ColorAnimationUsingKeyFramesExample
		Inherits Page
		Public Sub New()
			Title = "BooleanAnimationUsingKeyFrames Example"
			Background = Brushes.White
			Margin = New Thickness(20)

			' Create a NameScope for this page so that
			' Storyboards can be used.
			NameScope.SetNameScope(Me, New NameScope())

			Dim myStackPanel As New StackPanel()
			myStackPanel.Orientation = Orientation.Vertical
			myStackPanel.HorizontalAlignment = HorizontalAlignment.Center

			' Create the Border that is the target of the animation.
			Dim animatedBrush As New SolidColorBrush()
			animatedBrush.Color = Color.FromArgb(255, 0, 255, 0)
			Dim myBorder As New Border()

			' Set the initial color of the border to green.
			myBorder.BorderBrush = animatedBrush
			myBorder.BorderThickness = New Thickness(28)
			myBorder.Padding = New Thickness(20)
			myStackPanel.Children.Add(myBorder)

			' Create a TextBlock to host inside the Border.
			Dim myTextBlock As New TextBlock()
			myTextBlock.Text = "This example shows how to use the ColorAnimationUsingKeyFrames" & " to create an animation on the BorderBrush property of a Border."
			myBorder.Child = myTextBlock

			' Assign the Brush a name so that
			' it can be targeted by a Storyboard.
			Me.RegisterName("AnimatedBrush", animatedBrush)

			' Create a ColorAnimationUsingKeyFrames to
			' animate the BorderBrush property of the Button.
			Dim colorAnimation As New ColorAnimationUsingKeyFrames()
			colorAnimation.Duration = TimeSpan.FromSeconds(6)

			' Create brushes to use as animation values.
			Dim redColor As New Color()
			redColor = Color.FromArgb(255, 255, 0, 0)
			Dim yellowColor As New Color()
			yellowColor = Color.FromArgb(255, 255, 255, 0)
			Dim greenColor As New Color()
			greenColor = Color.FromArgb(255, 0, 255, 0)

			' Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
			' a smooth, linear animation between values.
			colorAnimation.KeyFrames.Add(New LinearColorKeyFrame(redColor, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.0)))) ' KeyTime -  Target value (KeyValue)

			' In the next half second, go to yellow. DiscreteColorKeyFrame creates a 
			' sudden jump between values.
			colorAnimation.KeyFrames.Add(New DiscreteColorKeyFrame(yellowColor, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.5)))) ' KeyTime -  Target value (KeyValue)

			' In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame 
			' creates a variable transition between values depending on the KeySpline property. In this example,
			' the animation starts off slow but toward the end of the time segment, it speeds up exponentially.
			colorAnimation.KeyFrames.Add(New SplineColorKeyFrame(greenColor, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4.5)), New KeySpline(0.6, 0.0, 0.9, 0.0))) ' KeySpline -  KeyTime -  Target value (KeyValue)

			' Set the animation to repeat forever. 
			colorAnimation.RepeatBehavior = RepeatBehavior.Forever

			' Set the animation to target the Color property
			' of the object named "AnimatedBrush".
			Storyboard.SetTargetName(colorAnimation, "AnimatedBrush")
			Storyboard.SetTargetProperty(colorAnimation, New PropertyPath(SolidColorBrush.ColorProperty))

			' Create a storyboard to apply the animation.
			Dim myStoryboard As New Storyboard()
			myStoryboard.Children.Add(colorAnimation)

			' Start the storyboard when the Border loads.
			AddHandler myBorder.Loaded, Sub(sender As Object, e As RoutedEventArgs) myStoryboard.Begin(Me)

			Content = myStackPanel
		End Sub

	End Class
End Namespace
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media;

namespace Microsoft.Samples.KeyFrameExamples
{
    public class ColorAnimationUsingKeyFramesExample : Page
    {
        public ColorAnimationUsingKeyFramesExample()
        {
            Title = "BooleanAnimationUsingKeyFrames Example";
            Background = Brushes.White;
            Margin = new Thickness(20);

            // Create a NameScope for this page so that 
            // Storyboards can be used.
            NameScope.SetNameScope(this, new NameScope());

            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Orientation = Orientation.Vertical;
            myStackPanel.HorizontalAlignment = HorizontalAlignment.Center;

            // Create the Border that is the target of the animation.
            SolidColorBrush animatedBrush = new SolidColorBrush();
            animatedBrush.Color = Color.FromArgb(255, 0, 255, 0);
            Border myBorder = new Border();

            // Set the initial color of the border to green.
            myBorder.BorderBrush = animatedBrush;
            myBorder.BorderThickness = new Thickness(28);
            myBorder.Padding = new Thickness(20);
            myStackPanel.Children.Add(myBorder);

            // Create a TextBlock to host inside the Border.
            TextBlock myTextBlock = new TextBlock();
            myTextBlock.Text = "This example shows how to use the ColorAnimationUsingKeyFrames"
                               + " to create an animation on the BorderBrush property of a Border.";
            myBorder.Child = myTextBlock;

            // Assign the Brush a name so that 
            // it can be targeted by a Storyboard. 
            this.RegisterName(
                "AnimatedBrush", animatedBrush);

            // Create a ColorAnimationUsingKeyFrames to 
            // animate the BorderBrush property of the Button.
            ColorAnimationUsingKeyFrames colorAnimation
                = new ColorAnimationUsingKeyFrames();
            colorAnimation.Duration = TimeSpan.FromSeconds(6);

            // Create brushes to use as animation values.
            Color redColor = new Color();
            redColor = Color.FromArgb(255, 255, 0, 0);
            Color yellowColor = new Color();
            yellowColor = Color.FromArgb(255, 255, 255, 0);
            Color greenColor = new Color();
            greenColor = Color.FromArgb(255, 0, 255, 0);

            // Go from green to red in the first 2 seconds. LinearColorKeyFrame creates 
            // a smooth, linear animation between values.
            colorAnimation.KeyFrames.Add(
                new LinearColorKeyFrame(
                    redColor, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.0))) // KeyTime
                );

            // In the next half second, go to yellow. DiscreteColorKeyFrame creates a  
            // sudden jump between values.
            colorAnimation.KeyFrames.Add(
                new DiscreteColorKeyFrame(
                    yellowColor, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.5))) // KeyTime
                );

            // In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame  
            // creates a variable transition between values depending on the KeySpline property. In this example, 
            // the animation starts off slow but toward the end of the time segment, it speeds up exponentially.
            colorAnimation.KeyFrames.Add(
                new SplineColorKeyFrame(
                    greenColor, // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4.5)), // KeyTime 
                    new KeySpline(0.6, 0.0, 0.9, 0.0) // KeySpline
                    )
                );

            // Set the animation to repeat forever. 
            colorAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the Color property 
            // of the object named "AnimatedBrush".
            Storyboard.SetTargetName(colorAnimation, "AnimatedBrush");
            Storyboard.SetTargetProperty(
                colorAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

            // Create a storyboard to apply the animation.
            Storyboard myStoryboard = new Storyboard();
            myStoryboard.Children.Add(colorAnimation);

            // Start the storyboard when the Border loads.
            myBorder.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                myStoryboard.Begin(this);
            };

            Content = myStackPanel;
        }

    }
}
<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ThicknessAnimationUsingKeyFrames Example">

  <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
    <Border Background="#99FFFFFF"  BorderThickness="28"
    Margin="0,60,0,20" Padding="20" >
      <Border.BorderBrush>
        <SolidColorBrush x:Name="MyAnimatedBrush" Color="Green" />
      </Border.BorderBrush>
      <Border.Triggers>
        <EventTrigger RoutedEvent="Border.Loaded">
          <BeginStoryboard>
            <Storyboard>

              <!-- Animate from green to red using a linear key frame, from red to 
              yellow using a discrete key frame, and from yellow back to green with
              a spline key frame. This animation repeats forever. -->
              <ColorAnimationUsingKeyFrames
                Storyboard.TargetProperty="Color"
                Storyboard.TargetName="MyAnimatedBrush"
                Duration="0:0:6" FillBehavior="HoldEnd" RepeatBehavior="Forever">
                <ColorAnimationUsingKeyFrames.KeyFrames>

                  <!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
                  a smooth, linear animation between values. -->
                  <LinearColorKeyFrame Value="Red" KeyTime="0:0:2" />

                  <!-- In the next half second, go to yellow. DiscreteColorKeyFrame creates a 
                  sudden jump between values. -->
                  <DiscreteColorKeyFrame Value="Yellow" KeyTime="0:0:2.5" />

                  <!-- In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame 
                  creates a variable transition between values depending on the KeySpline property. In this example,
                  the animation starts off slow but toward the end of the time segment, it speeds up exponentially.-->
                  <SplineColorKeyFrame Value="Green" KeyTime="0:0:4.5" KeySpline="0.6,0.0 0.9,0.00" />
                </ColorAnimationUsingKeyFrames.KeyFrames>
              </ColorAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Border.Triggers>

      <TextBlock>
        This example shows how to use the ColorAnimationUsingKeyFrames to create
        an animation on the BorderBrush property of a Border.
      </TextBlock>
    </Border>

  </StackPanel>
</Page>

For the complete sample, see KeyFrame Animation Sample.

Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.