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 开始的时间。 如果此时间线是根时间线,则时间相对于其交互式开始时间(触发时间线的时刻)。 此值可以是正值、负值或 null;null 值表示时间线永远不会播放。 默认值为零。

示例

时间线的 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 的行为就像它在过去某个时间开始一样。 例如,一个 BeginTime 为负 2.5 秒且 Duration 为 5 秒的 Timeline 在启动时显示为半途结束。

BeginTime 和 SpeedRatio

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

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

Dependency 属性信息

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

XAML 属性用法

< 对象BeginTime=“[-][.]小时小时:分钟[.fractionalSeconds]”/>

-或-

< 对象BeginTime=“[-][.]小时分钟”/>

-或-

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

-或-

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

XAML 值

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


System.Int32

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

小时
System.Int32

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

分钟
System.Int32

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


System.Int32

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

fractionalSeconds
System.Int32

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

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

适用于

另请参阅