Timeline.BeginTime Property

Gets or sets the time at which this Timeline should begin.

Namespace:  System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public Nullable<TimeSpan> BeginTime { get; set; }
<object BeginTime="[-][days.]hours:minutes:seconds[.fractionalSeconds]"/>- or -<object BeginTime="[-][days.]hours:minutes"/>- or - <object BeginTime="[-]days"/>- or -<object BeginTime="{x:Null Markup Extension}"/>

XAML Values

Items in square brackets ([ and ]) are optional.

days

System.Int32

A value greater than or equal to 0 that describes the number of days spanned by this begin time.

hours

System.Int32

A value between 0 and 23 that represents the number of hours spanned by this begin time.

minutes

System.Int32

A value between 0 and 59 that represents the number of minutes spanned by this begin time.

seconds

System.Int32

A value between 0 and 59 that represents the number of seconds spanned by this begin time.

fractionalSeconds

System.Int32

A value consisting of 1 to 7 digits that represents fractional seconds.

For the complete TimeSpan syntax, see the Remarks section of the Parse page.

Property Value

Type: System.Nullable<TimeSpan>
The time at which this Timeline should begin, relative to its parent's BeginTime. If this timeline is a root timeline, the time is relative to its interactive begin time (the moment at which the timeline was triggered). This value may be positive, negative, or null; a null value means the timeline never plays. The default value is zero.

Identifier field

BeginTimeProperty

Metadata properties set to true

None

The BeginTime property is useful for creating timelines that play in a sequence: by increasing the BeginTime of successive timelines that share the same parent, you can stagger their play times.

Negative Values

A negative BeginTime value causes a Timeline to behave as though it started at some time in the past. For example, a Timeline with a BeginTime of negative 2.5 seconds and a Duration of 5 seconds will appear to be half-way finished when it starts.

BeginTime and SpeedRatio

The time described by the BeginTime property is measured in the timeline's parent's time. For example, a timeline with a BeginTime of 5 whose parent has a SpeedRatio of 2 actually starts after 2.5 seconds.

A timeline's own SpeedRatio setting does not affect its BeginTime. For example, a timeline with a BeginTime of 5 seconds, a SpeedRatio of 2, and a parent timeline with a SpeedRatio of 1 starts after 5 seconds, not 2.5.

A timeline's BeginTime property determines the beginning of a timeline's active period. If the timeline has a parent timeline, the BeginTime property determines how long it takes the timeline to start after its parent starts. If the timeline is a root timeline (a Storyboard, for example), the BeginTime property determines how long the timeline takes to start playing after it is triggered.

The following example shows several different timelines with different BeginTime settings.


<!-- This example shows how the BeginTime property determines when a timeline starts.
     Several rectangles are animated by DoubleAnimations with identical 
     durations and target values, but with different
     BeginTime settings. -->

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  WindowTitle="BeginTime Example">
  <StackPanel Margin="20">

    <!-- The rectangles to animate. -->
    <Rectangle Name="DefaultBeginTimeRectangle" 
      Width="20" Height="20" Fill="Blue"  />

    <Rectangle Name="DelayedBeginTimeRectangle" 
      Width="20" Height="20" Fill="Blue"  />

    <Rectangle Name="DelayedAnimationWithDelayedParentRectangle" 
      Width="20" Height="20" Fill="Blue"  /> 

    <Rectangle Name="NegativeBeginTimeExampleRectangle" 
      Width="20" Height="20" Fill="Blue"  />            

    <!-- Create a button to start the animations. -->
    <Button Margin="20" Content="Start Animations">
      <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <BeginStoryboard>
            <Storyboard>

              <!-- This animation starts as soon as the button is clicked, because it
                   has a BeginTime of 0. -->
              <DoubleAnimation 
                Storyboard.TargetName="DefaultBeginTimeRectangle" 
                Storyboard.TargetProperty="Width"
                BeginTime="0:0:0" From="100" To="600" Duration="0:0:5"  /> 

              <!-- This animation starts 5 seconds after the button is clicked. -->
              <DoubleAnimation 
                Storyboard.TargetName="DelayedBeginTimeRectangle" 
                Storyboard.TargetProperty="Width"  
                BeginTime="0:0:5" From="100" To="600" Duration="0:0:5" />

              <ParallelTimeline BeginTime="0:0:5">  

              <!-- This animation starts 10 seconds after the button is clicked, 
                   because its parent has a BeginTime of 5 seconds and it has
                   a BeginTime of 5 seconds: 5 + 5 = 10.  -->              
                <DoubleAnimation  
                  Storyboard.TargetName="DelayedAnimationWithDelayedParentRectangle" 
                  Storyboard.TargetProperty="Width" 
                  BeginTime="0:0:5" From="100" To="600" Duration="0:0:5"  />
              </ParallelTimeline>

              <!-- This animation starts as soon as the button is clicked, but
                   it animates from 350 to 600 instead of from 100 to 600 
                   because of its negative BeginTime. The negative BeginTime
                   setting advances the animation, so that it behaves as though
                   it had already been playing for 2.5 seconds as soon as it is
                   started. -->
              <DoubleAnimation 
                Storyboard.TargetName="NegativeBeginTimeExampleRectangle" 
                Storyboard.TargetProperty="Width"  
                BeginTime="-0:0:2.5" From="100" To="600" Duration="0:0:5" />              

            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Button.Triggers>      
    </Button>

    <!-- This example demonstrates how the BeginTime property works on a root timeline. -->
    <Rectangle Name="RootTimelineWithDelayedBeginTimeRectangle"
      Width="20" Height="20" Fill="Blue" >
      <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
          <BeginStoryboard>
            <Storyboard BeginTime="0:0:5">

              <!-- This animation starts 5 seconds after the left mouse button
                   is pressed, because its parent storyboard (a root timeline)
                   has a BeginTime of 5 seconds. -->
              <DoubleAnimation 
                Storyboard.TargetName="RootTimelineWithDelayedBeginTimeRectangle" 
                Storyboard.TargetProperty="Width"
                BeginTime="0:0:0" From="100" To="600" Duration="0:0:2" />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Rectangle.Triggers>
    </Rectangle>    
  </StackPanel>
</Page>


More Code

How to: Simplify Animations by Using Child TimelinesThis example shows how to simplify animations by using child ParallelTimeline objects. A Storyboard is a type of Timeline that provides targeting information for the timelines it contains. Use a Storyboard to provide timeline targeting information, including object and property information.

.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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft