Share via


IXRDoubleAnimation (Windows Embedded CE 6.0)

1/6/2010

This class animates a float value between two target values by using linear interpolation over a duration set by the inherited method IXRTimeline::SetDuration.

Syntax

class IXRDoubleAnimation : public IXRTimeline

Methods

Method Description

IXRDoubleAnimation::GetBy

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

IXRDoubleAnimation::GetFrom

Retrieves the starting value of this animation.

IXRDoubleAnimation::GetTo

Retrieves the ending value of this animation.

IXRDoubleAnimation::SetBy

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

IXRDoubleAnimation::SetFrom

Sets the starting value of this animation.

IXRDoubleAnimation::SetTo

Sets the ending value of this 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 several 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 method to identify a target property to animate. You can use the attached properties Storyboard.TargetName and Storyboard.TargetProperty to identify the x:Name value of an object and the object's property to animate.

You can apply an animation to IXRFrameworkElement-derived objects that are created in C++ at run-time or parsed from Silverlight 2 XAML. For IXRDependencyObject-derived objects that do not inherit from IXRFrameworkElement, you can apply an animation only after the object is parsed from XAML and lives in the object tree.

The IXRDoubleAnimation class creates a transition between two target float values. To set its target values, use its SetFrom, SetTo, and SetBy methods. The following table summarizes how these methods can be used together or separately to determine an animation's target values.

Methods used Resulting behavior

SetFrom

The animation progresses from the value specified in SetFrom to the animated property’s default value or to the previous animation's output value, depending on how the previous animation is configured.

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 from a previous animation's output value to the value specified in SetTo.

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

SetBy

The animation progresses from the animated property's base value or from 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 methods, the value specified in SetTo takes precedence and the SetBy property is ignored.

To use other interpolation methods or to animate between more than two target values use the IXRDoubleAnimationUsingKeyFrames object.

You can also define this kind of animation in Microsoft Silverlight 2 XAML. 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.

Note

The name of this XAML element is generated by the Microsoft Expression Blend 2 IDE and includes "double" in order to maintain parity with the name of its equivalent XAML element in the source XAML markup. However, in Silverlight this object represents a float instead of a double.

Example

The following example code animates the Angle property of a <RotateTransform> element that is defined in the source XAML. This causes the rectangle that has this rotate transformation to constantly rotate around its center point.

XAML Markup:
<Canvas x:Name="myCanvas>
  <Rectangle x:Name="myRectangle">
    <Rectangle.RotateTransform>
      <RotateTransform x:Name="myRTransform" Angle="45" CenterX="50" CenterY="50" />
    </Rectangle.RotateTransform>
  </Rectangle>
</Canvas>

C++ Code:
#include <windows.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>


void AnimateRotateTransform(IXRApplication* pApplication, IXRFrameworkElement* pVisualRoot, 
  XRRepeatBehavior* myForeverRepeatStruct)
{

  // Create an animation and storyboard to animate a rectangle's angle value
  IXRDoubleAnimationPtr myAnimation;
  IXRStoryboardPtr myStoryboard;
  IXRTimelineCollectionPtr childAnimations;

  float newAngle = 360;

  pApplication->CreateObject(IID_IXRDoubleAnimation, &myAnimation);
  pApplication->CreateObject(IID_IXRStoryboard, &myStoryboard);

  myAnimation->SetAttachedProperty(L"Storyboard.TargetName", L"myRTransform");
  myAnimation->SetAttachedProperty(L"Storyboard.TargetProperty", L"Angle");
  myAnimation->SetTo(newAngle);
  myAnimation->SetRepeatBehavior(myForeverRepeatStruct);

  myStoryboard->GetChildren(&childAnimations);
  childAnimations->Add(myAnimation, NULL);


  // Get a pointer to the canvas on which the rectangle is positioned
  IXRCanvasPtr pCanvas;
  IXRRectanglePtr pRect;
  IXRResourceDictionaryPtr canvasResources;
  int index = 0;

  pVisualRoot->FindName(L"MyCanvas", &pCanvas);
  pCanvas->GetResources(&canvasResources);

  // Add the new storyboard to the element tree
  canvasResources->Add(myStoryboard, index);

  // attach a delegate to an event in the rectangle object that represents the 
  // animation event handler

  CustomEventHandlers* myHandlerObject;

  pVisualRoot->FindName(L"myRectangle", &pRect);
  pRect->AddMouseLeftButtonDownEventHandler(CreateDelegate(&myHandlerObject, &CustomEventHandlers::OnMouseLeftButtonDown));
}

class CustomEventHandlers 
  {
   public:
     HRESULT OnMouseLeftButtonDown(IXRDependencyObject* pSender, XRMouseEventArgs* pArgs)
     {
          // play the storyboard on-screen
      
         // First make sure that the storyboard not playing
        myStoryboard.Stop();
       
         // Begin to play the storyboard animation
         myStoryboard.Begin();
     }

To run this code example, you must parse the source XAML for the application, including the markup code, into an object tree in the visual host. Additionally, both an IXRApplication instance (pApplication) and a visual root (pVisualRoot) must already be created. For more information about the classes used in this example, see IXRApplication, IXRVisualHost, IXRStoryboard, and IXRCanvas.

Inheritance Hierarchy

IXRDependencyObject

    IXRTimeline

        IXRDoubleAnimation

.NET Framework Equivalent

System.Windows.Media.Animation.DoubleAnimation

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

Other Resources