Partager via


IXRColorAnimation (Compact 2013)

3/28/2014

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

Syntax

class IXRColorAnimation : public IXRTimeline

Inheritance Hierarchy

IXRDependencyObject

    IXRTimeline

        IXRColorAnimation

Functions

Function

Description

IXRColorAnimation::GetBy

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

IXRColorAnimation::GetEasingFunction

Retrieves the easing function that is applied to this 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::SetEasingFunction

Sets the easing function that is applied to this animation.

IXRColorAnimation::SetFrom

Sets the starting value of the animation.

IXRColorAnimation::SetTo

Sets the ending value of the animation.

Thread Safety

Members of this class are thread safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

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 IXRColorAnimation::SetEasingFunction method, or use the IXRColorAnimationUsingKeyFrames object.

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

When you create a class instance, use an IXRColorAnimationPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

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

Description

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.

Code

#include "windows.h"
#include "XamlRuntime.h"
#include "XRPtr.h"

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

  pApplication->CreateObject(&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 = XRTimeSpan(50000);
  IXRColorAnimationPtr pColorAnimation;

  pApplication->CreateObject(&pColorAnimation);
  pColorAnimation->SetAttachedProperty(L"Storyboard.TargetName", NULL, L"NewRectangle");
  pColorAnimation->SetAttachedProperty(L"Storyboard.TargetProperty", NULL, L"Fill");
  pColorAnimation->SetFrom(startBrushColor);
  pColorAnimation->SetTo(newBrushColor);
  pColorAnimation->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.

  IXRTimelineCollectionPtr pChildrenAnimations;
  

  pStoryboard->GetChildren(&pChildrenAnimations);
  pChildrenAnimations->Add(pColorAnimation, NULL);
}

Comments

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.

.NET Framework Equivalent

System.Windows.Media.Animation.ColorAnimation

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Animation Storyboards
Classes for Visual Appearance
IXRStoryboard