Compartilhar via


IXRDoubleAnimation (Compact 2013)

3/28/2014

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

Syntax

class IXRDoubleAnimation : public IXRTimeline

Inheritance Hierarchy

IXRDependencyObject

    IXRTimeline

        IXRDoubleAnimation

Methods

Method

Description

IXRDoubleAnimation::GetBy

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

IXRDoubleAnimation::GetEasingFunction

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

Sets the easing function that is applied to this animation.

IXRDoubleAnimation::SetFrom

Sets the starting value of this animation.

IXRDoubleAnimation::SetTo

Sets the ending value of this 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 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 3 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 IXRDoubleAnimation::SetEasingFunction method, or use the IXRDoubleAnimationUsingKeyFrames object.

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

You can also define this kind of animation in Microsoft Silverlight 3 XAML. 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 DoubleAnimation Class at MSDN.

Note

The name of this XAML element is generated by the Blend for Visual Studio IDE and includes "double" in order to maintain parity with the name of its equivalent XAML element in the source XAML markup. However, in XAML for Windows Embedded 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.

Important

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

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.

.NET Framework Equivalent

System.Windows.Media.Animation.DoubleAnimation

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Animation Storyboards
Classes for Visual Appearance