Timeline.BeginTime Timeline.BeginTime Timeline.BeginTime Timeline.BeginTime Property


获取或设置此 Timeline 应开始的时间。Gets or sets the time at which this Timeline should begin.

 property Nullable<TimeSpan> BeginTime { Nullable<TimeSpan> get(); void set(Nullable<TimeSpan> value); };
public Nullable<TimeSpan> BeginTime { get; set; }
member this.BeginTime : Nullable<TimeSpan> with get, set
Public Property BeginTime As Nullable(Of TimeSpan)


相对于其父级的 BeginTime,此 Timeline 应开始的时间。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). 此值可能为正数、负数或 nullnull 值表示永远不会播放该时间线。This value may be positive, negative, or null; a null value means the timeline never plays. 默认值为 0。The default value is zero.


时间线的BeginTime属性确定时间线活动期间的开始时间。A timeline's BeginTime property determines the beginning of a timeline's active period. 如果时间线具有父时间线, 则BeginTime该属性确定时间线在其父项启动后的启动时间。If the timeline has a parent timeline, the BeginTime property determines how long it takes the timeline to start after its parent starts. 如果时间线是根时间线 ( Storyboard例如), 则BeginTime属性确定时间线在触发后开始播放的时间。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.

下面的示例显示了几个具有不同BeginTime设置的不同时间线。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" 
  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">
        <EventTrigger RoutedEvent="Button.Click">

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

              <!-- This animation starts 5 seconds after the button is clicked. -->
                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.  -->              
                  BeginTime="0:0:5" From="100" To="600" Duration="0:0:5"  />
              <!-- 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. -->
                BeginTime="-0:0:2.5" From="100" To="600" Duration="0:0:5" />              
    <!-- This example demonstrates how the BeginTime property works on a root timeline. -->
    <Rectangle Name="RootTimelineWithDelayedBeginTimeRectangle"
      Width="20" Height="20" Fill="Blue" >
        <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
            <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. -->
                BeginTime="0:0:0" From="100" To="600" Duration="0:0:2" />


属性可用于创建按顺序播放的时间线: 通过BeginTime增加共享同一父项的连续时间线, 你可以错开其播放时间。 BeginTimeThe 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

负值BeginTime导致的Timeline行为就像它在过去某个时间开始一样。A negative BeginTime value causes a Timeline to behave as though it started at some time in the past. 例如, 如果为Timeline BeginTime负2.5 秒,为5秒,则在开始时,将显示为半双向完成。DurationFor 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.

System.windows.media.animation.timeline.begintime 和 SpeedRatioBeginTime and SpeedRatio

BeginTime属性所描述的时间是在时间线的 parent's 时间内计量的。The time described by the BeginTime property is measured in the timeline's parent's time. 例如, 其父级BeginTime SpeedRatio为5的时间线实际上在2.5 秒后开始。For example, a timeline with a BeginTime of 5 whose parent has a SpeedRatio of 2 actually starts after 2.5 seconds.

时间线本身SpeedRatio的设置不影响它BeginTime的。A timeline's own SpeedRatio setting does not affect its BeginTime. 例如, 如果时间线BeginTime的为5秒, a SpeedRatio为 2, 并且父时间线SpeedRatio为 1, 则在5秒后开始, 而不是2.5。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.

依赖项属性信息Dependency Property Information

标识符字段Identifier field BeginTimeProperty
元数据属性设置为trueMetadata properties set to true NoneNone

XAML 属性用法XAML Attribute Usage

<对象= "[-] [days.] BeginTime小时:分钟:[。fractionalSeconds] "/><object BeginTime="[-][days.]hours:minutes:seconds[.fractionalSeconds]"/>


<对象= "[-] [days.] BeginTime小时:分钟"/><object BeginTime="[-][days.]hours:minutes"/>

- 或 --or-

<object BeginTime="[-]days"/><object BeginTime="[-]days"/>


<对象= "{x:Null 标记扩展}"/> BeginTime<object BeginTime="{x:Null Markup Extension}"/>


方括号 ([]) 中的项是可选的。Items in square brackets ([ and ]) are optional.


一个大于或等于0的值, 该值描述此开始时间跨越的天数。A value greater than or equal to 0 that describes the number of days spanned by this begin time.


一个介于0和23之间的值, 表示此开始时间跨越的小时数。A value between 0 and 23 that represents the number of hours spanned by this begin time.


一个介于0和59之间的值, 该值表示此开始时间跨越的分钟数。A value between 0 and 59 that represents the number of minutes spanned by this begin time.


一个介于0和59之间的值, 该值表示此开始时间跨越的秒数。A value between 0 and 59 that represents the number of seconds spanned by this begin time.


由1到7位数字组成的值, 表示秒的小数部分。A value consisting of 1 to 7 digits that represents fractional seconds.

有关完整TimeSpan的语法, 请参阅Parse页面的 "备注" 部分。For the complete TimeSpan syntax, see the Remarks section of the Parse page.