KeyTime 結構

定義

指定特定的主要畫面格在動畫中的發生時機。

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
struct KeyTime
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public struct KeyTime
Public Structure KeyTime
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
繼承
KeyTime
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

此範例使用 XAML 屬性語法,在數種類型的DoubleAnimationUsingKeyFrames類別上設定KeyTime值。

<Canvas>
    <Canvas.Resources>
        <Storyboard x:Name="myStoryboard">

            <!-- Animate the TranslateTransform's X property
           from 0 to 350, then 50, then 200 over 10 seconds. -->
            <DoubleAnimationUsingKeyFrames
       Storyboard.TargetName="MyAnimatedTranslateTransform"
       Storyboard.TargetProperty="X"
       Duration="0:0:10" EnableDependentAnimation="True">

                <!-- Using a LinearDoubleKeyFrame, the rectangle moves 
           steadily from its starting position to 500 over 
           the first 3 seconds.  -->
                <LinearDoubleKeyFrame Value="500" KeyTime="0:0:3" />

                <!-- Using a DiscreteDoubleKeyFrame, the rectangle suddenly 
           appears at 400 after the fourth second of the animation. -->
                <DiscreteDoubleKeyFrame Value="400" KeyTime="0:0:4" />

                <!-- Using a SplineDoubleKeyFrame, the rectangle moves 
           back to its starting point. The animation starts out slowly at 
           first and then speeds up. This KeyFrame ends after the 6th
           second. -->
                <SplineDoubleKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0" KeyTime="0:0:6" />

            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Canvas.Resources>

    <Rectangle PointerPressed="Pointer_Clicked" Fill="Blue"
 Width="50" Height="50">
        <Rectangle.RenderTransform>
            <TranslateTransform x:Name="MyAnimatedTranslateTransform" />
        </Rectangle.RenderTransform>
    </Rectangle>

</Canvas>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
    myStoryboard.Begin();
}
' Start the animation when the object loads
Private Sub Start_Animation(ByVal sender As Object, ByVal e As EventArgs)
    myStoryboard.Begin()
End Sub

備註

每個主要畫面格的 KeyTime 屬性都會指定該主要畫面格結束的時間。 它不會指定主要畫面格播放的時間長度。 主要畫面格的播放時間量取決於主要畫面格的結束時間、前一個主要畫面格的結束時間,以及動畫的持續期間。

只以整數指定 KeyTime,而不需任何時間範圍常值字元,例如 將會產生該天數的 KeyTime! 這很少會是預期的結果。 通常您會以秒為單位指定時間範圍。 因此,KeyTime 字串通常會包含小時和分鐘之前的零值,以及常值 作為小時、分鐘和秒之間的分隔符號。 例如,若要指定 KeyTime 為 5 秒,正確的字串是 「0:0:5」 (「0:0:05」 相當於) 。

XAML 語法的注意事項

您無法將 KeyTime 宣告為 ResourceDictionary中的可共用物件。

KeyTime 的投影和成員

如果您使用 Microsoft .NET 語言 (C# 或 Microsoft Visual Basic) ,或 Visual C++ 元件延伸模組 (C++/CX) ,則 KeyTime 有一些公用程式方法,而且其資料成員 TimeSpan 會公開為唯讀屬性,而不是欄位。

對於 Microsoft .NET,Duration會針對其 TimeSpan、FromTimeSpan 方法和Implicit運算子公開TimeSpan.Parse Visual C++ 元件延伸模組中的結構無法使用這些元件延伸模組, (C++/CX) ,但您可以使用 KeyTimeHelper.FromTimeSpan

如果您使用 Windows 執行階段 範本庫 (WRL) 使用 C++ 進行程式設計,則只有資料成員欄位TimeSpan是 KeyTime 的成員。 WRL 程式碼可以存取 FromTimeSpan ,因為它存在於 KeyTimeHelper 類別上。

欄位

TimeSpan

這個 KeyTime 的時間元件。

適用於