Partager via


IXRColorAnimation (Windows Embedded CE 6.0)

1/6/2010

This class animates a color value between two target values by using linear interpolation over a specified duration, which is set by the inherited method IXRTimeline::SetDuration.

Syntax

class IXRColorAnimation : public IXRTimeline

Functions

Function Description

IXRColorAnimation::GetBy

Retrieves the total difference between the starting and ending values of the animation.

IXRColorAnimation::GetFrom

Retrieves the starting value of the animation.

IXRColorAnimation::GetTo

Retrieves the ending value of the animation.

IXRColorAnimation::SetBy

Sets the total difference between the starting and ending values of the animation.

IXRColorAnimation::SetFrom

Sets the starting value of the animation.

IXRColorAnimation::SetTo

Sets the ending value of the animation.

Remarks

An animation updates the value of a property over a period of time. An animation effect can be subtle, such as moving an IXRShape object a few pixels left or right, or dramatic, such as enlarging an object to 200 times its original size while spinning it and changing its color. To create an animation, use the inherited IXRDependencyObject::SetAttachedProperty function to identify a target property to animate.

The IXRColorAnimation class creates a transition between two target values. To set its target values, use its SetFrom, SetTo, and SetBy functions. The following table summarizes how these functions can be used together or separately to determine the target values of an animation.

Function(s) used by the developer Resulting behavior

SetFrom

The animation progresses from the value specified in SetFrom to the base value of the property being animated.

SetFrom and SetTo

The animation progresses from the value specified in SetFrom to the value specified in SetTo.

SetFrom and SetBy

The animation progresses from the value specified in SetFrom to the sum of the values specified in SetFrom and SetBy.

SetTo

The animation progresses from the animated property's base value or a previous animation's output value to the value specified in SetTo.

SetBy

The animation progresses from the animated property's base value or a previous animation's output value to the sum of that value and the value specified in SetBy.

If you use both the SetTo and SetBy functions, the value specified in SetTo takes precedence and the SetBy property is ignored.

To use other interpolation methods or to define an animation that progresses through more than two target values use the IXRColorAnimationUsingKeyFrames object.

A collection of animation storyboards, including IXRColorAnimation objects, belongs to an IXRStoryboard object.

You can also define a color animation in Microsoft Silverlight 2. For information about the differences between XAML in Silverlight for Windows Embedded and Silverlight 2, see Differences Between Silverlight for the Web and Silverlight for Windows Embedded. For more information about how to define this element in the source XAML for your application, see this Microsoft Web site.

Ee503658.collapse(en-US,WinEmbedded.60).gifDescription

The following code example defines new color values, sets the Fill property of a rectangle defined in source XAML as the animation target, and creates an animation storyboard that will animate the color of the interior of the rectangle at run-time.

Note

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

Ee503658.collapse(en-US,WinEmbedded.60).gifCode

#include "XamlRuntime.h"

void CreateAnimationForStoryboard(IXRApplication* pApplication, IXRVisualRoot* pVisualRoot, IXRStoryboard* myStoryboard)
{
  // Create a new rectangle
  IXRRectangle* pRect;
  float rHeight = 100;
  float rWidth = 50;

  pApplication->CreateObject(IID_IXRRectangle, &pRect);
  pRect->SetWidth(&rWidth);
  pRect->SetHeight(&rHeight);
  pRect->SetName(L"NewRectangle");

  // Define some new solid color values
  COLORREF startBrushColor = RGB(0,50,100);
  COLORREF newBrushColor = RGB(0,50,0);

  // Now create an animation that will change the interior of the Rectangle 
  // to a new color when triggered

  XRTimeSpan ColoringTime = { 50000 };
  IXRColorAnimation* myColorAnimation;

  pApplication->CreateObject(IID_IXRColorAnimation, &myColorAnimation);
  myColorAnimation->SetAttachedProperty(L"Storyboard.TargetName", L"NewRectangle");
  myColorAnimation->SetAttachedProperty(L"Storyboard.TargetProperty", L"Fill");
  myColorAnimation->SetFrom(startBrushColor);
  myColorAnimation->SetTo(newBrushColor);
  myColorAnimation->SetBeginTime(ColoringTime);

  // Add myColorAnimation to a storyboard's collection of animations. 
  // When you call myStoryboard.Begin from within an event handler, 
  // its child animation, myColorAnimation, is triggered.

  IXRTimelineCollection* pChildrenAnimations;
  UINT* index;

  myStoryboard->GetChildren(&pChildrenAnimations);
  pChildrenAnimations->Add(&myColorAnimation, &index);
}

Ee503658.collapse(en-US,WinEmbedded.60).gifComments

To run this code example, the IXRApplication instance must already be created, the visual tree must already be generated, the rectangle defined in XAML must be parsed into an IXRRectangle object, and an IXRStoryboard instance must already be created to represent an object that is stored in the visual tree.

Inheritance Hierarchy

IXRDependencyObject

    IXRTimeline

        IXRColorAnimation

.NET Framework Equivalent

System.Windows.Media.Animation.ColorAnimation

Requirements

Header XamlRuntime.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for Visual Appearance and Behavior
IXRStoryboard