Timeline.BeginTime 属性

定义

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

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

属性值

Nullable<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. 默认值为零。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" 
  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>

注解

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

负值 BeginTime 值使 Timeline 的行为如同过去一段时间内的情况。A negative BeginTime value causes a Timeline to behave as though it started at some time in the past. 例如,如果 TimelineBeginTime 为2.5 秒,Duration 为5秒,则会在启动时显示为半双向完成。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.

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 为5的时间线(其父 SpeedRatio 为2)实际上在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 设置不会影响其 BeginTimeA timeline's own SpeedRatio setting does not affect its BeginTime. 例如,时间线的 BeginTime 为5秒,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 None

XAML 特性用法XAML Attribute Usage

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

-或--or-

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

-或--or-

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

-或--or-

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

XAML 值XAML Values

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

天数days
System.Int32

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

小时数hours
System.Int32

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

分钟数minutes
System.Int32

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

secondsseconds
System.Int32

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

fractionalSecondsfractionalSeconds
System.Int32

由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.

适用于

另请参阅