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)

屬性值

這個 Timeline 應該開始的時間,相對於其父項的 BeginTime。 如果這個時間表是根時間表,則時間相對於其互動開始時間 (觸發時間表的時間)。 這個值可以是正數、負數或 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 時間軸的 ,其父系的 SpeedRatio 2 實際上會在 2.5 秒後開始。

時程表本身 SpeedRatio 的設定不會影響其 BeginTime 。 例如,時間軸 BeginTime 的 5 秒、 SpeedRatio 2 的 ,以及 1 的父時間軸 SpeedRatio 在 5 秒後開始,而不是 2.5。

相依性屬性資訊

識別碼欄位 BeginTimeProperty
中繼資料屬性設定為 true

XAML Attribute Usage

<物件BeginTime=「[-][days.]hoursminutesseconds[.fractionalSeconds]「/>

-或-

<物件BeginTime=「[-][days.]hoursminutes「/>

-或-

<物件BeginTime=「[-]days」/>

-或-

<物件BeginTime=「{x:Null 標記延伸}」/>

XAML 值

方括弧 ([]) 中的專案是選擇性專案。

days
System.Int32

大於或等於 0 的值,描述此開始時間跨越的天數。

hours
System.Int32

介於 0 到 23 之間的值,表示這個開始時間跨越的時數。

minutes
System.Int32

介於 0 到 59 之間的值,表示這個開始時間跨越的分鐘數。

seconds
System.Int32

介於 0 到 59 之間的值,表示這個開始時間跨越的秒數。

fractionalSeconds
System.Int32

值,包含代表小數秒的 1 到 7 位數。

如需完整的 TimeSpan 語法,請參閱頁面的 Parse 一節。

適用於

另請參閱