次の方法で共有


IXRStoryboard (Windows Embedded CE 6.0)

1/6/2010

This class controls the playback of animations with a timeline and provides information used to target objects and properties for its child animations.

Syntax

class IXRStoryboard : public IXRTimeline

Methods

Method Description

IXRStoryboard::Begin

Starts the set of animations associated with this storyboard.

IXRStoryboard::GetChildren

Retrieves the collection of child animations as objects derived from IXRTimeline.

IXRStoryboard::GetCurrentState

Retrieves the clock state of this storyboard.

IXRStoryboard::GetCurrentTime

Retrieves the current time span of this storyboard.

IXRStoryboard::Pause

Pauses the animation clock of this storyboard.

IXRStoryboard::Resume

Resumes the animation clock of this storyboard.

IXRStoryboard::Seek

Advances this storyboard to the specified position in the timeline. The storyboard performs the requested seek when the next clock tick occurs.

IXRStoryboard::SeekAlignedToLastTick

Advances this storyboard to a new position from the current position based on a specified time increment (synchronously).

IXRStoryboard::SkipToFill

Advances this storyboard's clock to the end of its active period.

IXRStoryboard::Stop

Stops the playback of this storyboard.

Remarks

You can use the interactive methods in the IXRStoryboard class to start, pause, resume, and stop an animation.

You can use an IXRStoryboard object as a container for both individual animation objects (for example, IXRColorAnimation) and also child storyboard objects that contain their own animation collections. When an IXRStoryboard contains IXRStoryboard objects in its child collection, this is referred to as nestingIXRStoryboard objects within one another.

Implementing nested storyboards can help you create complex animation sequences. Each child storyboard waits until its parent storyboard begins before it starts the countdown for its own start time. You can add a new storyboard object to another Silverlight object by using IXRBeginStoryboard::SetStoryboard or IXRVisualTransition::SetStoryboard, or by adding it to the collection retrieved by IXRFrameworkElement::GetResources.

You can retrieve a storyboard's IXRTimelineCollection object by calling IXRStoryboard::GetChildren, and then you can manipulate the collection by adding objects to it. Then you can specify begin-time values for each nested IXRStoryboard separately by using its inherited method IXRTimeline::SetBeginTime.

To create a collection of IXRStoryboard objects that play when a framework element raises the OnLoaded event, create IXRBeginStoryboard objects and add an IXRStoryboard to each one by calling IXRBeginStoryboard::SetStoryboard.

You can also define a storyboard in 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.

Example

The following example code creates a new storyboard, adds animations to it, and then adds it as a new resource for an IXRCanvas object in the visual tree. It also shows how to start the animation within event handling code.

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.

#include <windows.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>


// Create an event handler that plays the animation. 
// The following code shows a simple event handler as a starting point

class CustomEventHandlers 
{
 public:
    IXRVisualHost* g_pHost;

    HRESULT  SetHost(IXRVisualHost* pHost)
       {
            HRESULT hr;
            ASSERT(! g_pHost);
            if(NULL == pHost)
            {
                 hr = S_FALSE;
                 return hr;
            
            }
            
            g_pHost = pHost;
            g_pHost->AddRef();
           hr = S_OK;
            return hr;
       }


     HRESULT OnMouseEnter(IXRDependencyObject* pSender, XRMouseEventArgs* pArgs)
     {
   IXRFrameworkElementPtr pRoot;
   IXRStoryboardPtr pStoryboard;
       g_pHost->GetRootElement(&pRoot);
   pRoot->FindName(L"NewStoryboard", &pStoryboard);

      // play the storyboard on-screen
      
       // First make sure that the storyboard not playing
       pStoryboard->Stop();
       
       // Begin playing the storyboard animation
       pStoryboard->Begin();
     }
};

// Create the animation storyboard

void CreateStoryboard(IXRApplication* pApplication, IXRColorAnimation* myColorAnimation, 
  IXRPointAnimation* myPointAnimation, XRDuration* myDefinedDuration, 
  IXRCanvas* pCanvas, CustomEventHandlers* myHandlerObject)
{
   // Create a new storyboard for the child animations that were
   // provided as [in] parameters

   IXRStoryboard* myStoryboard;
   IXRTimelineCollection* childAnimations;
   bool AutoReverseSetting = true;

   pApplication->CreateObject(IID_IXRStoryboard, &myStoryboard);

   myStoryboard->GetChildren(&childAnimations);

   childAnimations->Add(myColorAnimation, NULL);
   childAnimations->Add(myPointAnimation, NULL);
  
   myStoryboard->SetName(L"NewStoryboard");
   myStoryboard->SetDuration(myDefinedDuration);
   myStoryboard->SetAutoReverse(AutoReverseSetting);

   // Add the new storyboard to a canvas that is in the visual tree
   
   IXRResourceDictionary* canvasResources;
   pCanvas->GetResources(&canvasResources);
   canvasResources->Add(myStoryboard, NULL);

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

   pCanvas->AddMouseEnterEventHandler(CreateDelegate(&myHandlerObject, &CustomEventHandlers::OnMouseEnter));

}

To run the previous code sample, you must already have created an IXRCanvas object with the name MyAnimatedCanvas in the visual tree and both the IXRPointAnimation and IXRColorAnimation objects that this code example adds to the animation storyboard.

To begin a storyboard animation for a storyboard that was defined in the Silverlight 2 XAML, you can locate it from the event handling code by calling IXRFrameworkElement::FindName and passing in the x:Name string defined for the <Storyboard> element.

Inheritance Hierarchy

IXRDependencyObject

    IXRTimeline

        IXRStoryboard

.NET Framework Equivalent

System.Windows.Media.Animation.Storyboard

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