Timeline.BeginTime 属性

定义

获取或设置此 Timeline 应开始的时间。

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)

属性值

相对于其父级的 BeginTime,此 Timeline 应开始的时间。 如果此时间线为根时间线,则该时间相对于其交互开始时间(触发时间线的时刻)。 此值可能为正数、负数或 nullnull 值表示永远不会播放该时间线。 默认值为零。

示例

时间线的 BeginTime 属性确定时间线活动时段的开始时间。 如果时间线具有父时间线,则 BeginTime 属性确定时间线在父级启动后需要多长时间。 如果时间线是 (Storyboard的根时间线,例如) ,则 BeginTime 属性确定时间线在触发后开始播放所需的时间。

以下示例显示了具有不同设置的多个不同 BeginTime 时间线。

<!-- 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 共享同一父级的连续时间线,可以错开它们的播放时间。

负值

BeginTime 值会导致 Timeline 的行为就像在过去某个时间启动一样。 例如,一个TimelineBeginTime为负 2.5 秒、一个Duration为 5 秒的 当启动时,它看起来是半途完成的。

BeginTime 和 SpeedRatio

属性描述 BeginTime 的时间以时间线的父时间度量。 例如,具有 5 个的时间线 BeginTime ,其父级的 a SpeedRatio 为 2 实际上在 2.5 秒后开始。

时间线自己的 SpeedRatio 设置不会影响其 BeginTime。 例如,具有 BeginTime 5 秒、2 的 SpeedRatio 父时间线和 1 的 SpeedRatio 父时间线在 5 秒(而不是 2.5)后开始。

依赖项属性信息

标识符字段 BeginTimeProperty
元数据属性设置为 true

XAML 属性用法

<对象BeginTime=“[-][days.]hoursminutesseconds[.fractionalSeconds]“/>

-或-

<对象BeginTime=“[-][days.]hoursminutes“/>

-或-

<对象BeginTime=“[-]days”/>

-或-

<对象BeginTime=“{x:Null 标记扩展}”/>

XAML 值

方括号中的项 ([]) 是可选的。

days
System.Int32

一个大于或等于 0 的值,用于描述此开始时间所跨越的天数。

小时数
System.Int32

一个介于 0 和 23 之间的值,表示此开始时间所跨越的小时数。

minutes
System.Int32

一个介于 0 和 59 之间的值,表示此开始时间所跨越的分钟数。

seconds
System.Int32

介于 0 和 59 之间的值,表示此开始时间所跨越的秒数。

fractionalSeconds
System.Int32

一个值,该值由 1 到 7 位表示秒的小数位数组成。

有关完整 TimeSpan 语法,请参阅页面的 Parse “备注”部分。

适用于

另请参阅