Export (0) Print
Expand All
Expand Minimize

ClockState Enumeration

Describes the potential states of a timeline's Clock object.

Namespace:  System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)

public enum ClockState
<object property="enumerationMemberName" .../>

Member nameDescription
ActiveThe current Clock time changes in direct relation to that of its parent. If the timeline is an animation, it is actively affecting targeted properties, so their value may change from tick (a sampling point in time) to tick. If the timeline has children, they may be Active, Filling, or Stopped.
FillingThe Clock timing continues, but does not change in relation to that of its parent. If the timeline is an animation, it is actively affecting targeted properties, but its values don't change from tick to tick. If the timeline has children, they may be Active, Filling, or Stopped.
StoppedThe Clock timing is halted, making the clock's current time and progress values undefined. If this timeline is an animation, it no longer affects targeted properties. If this timeline has children, they are also Stopped.

Note that ClockState does not indicate whether a clock is paused or the direction in which time is flowing.

These explanations rely on the concept of ticks; for a detailed explanation see the Animation and Timing System Overview.

A clock's CurrentStateInvalidated event occurs when its CurrentState becomes invalid, such as when the clock starts or stops. You can register for this event with directly using a Clock, or you can register using a Timeline.

In the following example, a Storyboard and two DoubleAnimation objects are used to animate the width of two rectangles. The CurrentStateInvalidated event is used to listen for clock state changes.


<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="Microsoft.Samples.Animation.TimingBehaviors.StateExample"
  Background="LightGray">
  <StackPanel Margin="20">

    <TextBlock 
      Name="ParentTimelineStateTextBlock"></TextBlock>
    <TextBlock 
      Name="Animation1StateTextBlock"></TextBlock>
    <Rectangle 
      Name="Rectangle01"
      Width="100" Height="50" Fill="Orange" />    
    <TextBlock Name="Animation2StateTextBlock"></TextBlock>
    <Rectangle 
      Name="Rectangle02"
      Width="100" Height="50" Fill="Gray" />  

    <Button Content="Start Animations" Margin="20">
      <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <BeginStoryboard>
            <Storyboard RepeatBehavior="2x" AutoReverse="True"
              CurrentStateInvalidated="parentTimelineStateInvalidated" >
              <DoubleAnimation
                Storyboard.TargetName="Rectangle01"
                Storyboard.TargetProperty="Width"
                From="10" To="200" Duration="0:0:9"
                BeginTime="0:0:1" 
                CurrentStateInvalidated="animation1StateInvalidated"/>
              <DoubleAnimation
                Storyboard.TargetName="Rectangle02"
                Storyboard.TargetProperty="Width"
                From="10" To="200" Duration="0:0:8"
                BeginTime="0:0:1" 
                CurrentStateInvalidated="animation2StateInvalidated" />            
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Button.Triggers>
    </Button>


  </StackPanel>
</Page>



using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace Microsoft.Samples.Animation.TimingBehaviors
{

    public partial class StateExample : Page
    {        

        private void parentTimelineStateInvalidated(object sender, EventArgs args)
        {
            Clock myClock = (Clock)sender;
            ParentTimelineStateTextBlock.Text += 
                myClock.CurrentTime.ToString() + ":" 
                + myClock.CurrentState.ToString() + " ";        
        }

        private void animation1StateInvalidated(object sender, EventArgs args)
        {

            Clock myClock = (Clock)sender;

            Animation1StateTextBlock.Text += 
                myClock.Parent.CurrentTime.ToString() + ":" 
                + myClock.CurrentState.ToString() + " ";     
        }

        private void animation2StateInvalidated(object sender, EventArgs args)
        {

            Clock myClock = (Clock)sender;
            Animation2StateTextBlock.Text += 
                myClock.Parent.CurrentTime.ToString() + ":" 
                + myClock.CurrentState.ToString() + " ";                 
        }
    }
}


The following illustration shows the different states the animations enter as the parent timeline (Storyboard) progresses.

Clock states for a Storyboard with two animations

The following table shows the times at which Animation1's CurrentStateInvalidated event fires:

Time (Seconds)

1

10

19

21

30

39

State

Active

Active

Stopped

Active

Active

Stopped

The following table shows the times at which Animation2's CurrentStateInvalidated event fires:

Time (Seconds)

1

9

11

19

21

29

31

39

State

Active

Filling

Active

Stopped

Active

Filling

Active

Stopped

Notice that Animation1's CurrentStateInvalidated event fires at 10 seconds, even though its state remains Active. That's because its state changed at 10 seconds, but it changed from Active to Filling and then back to Active in the same tick.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft