Bagikan melalui


KeyTime Struktur

Definisi

Menentukan kapan bingkai kunci tertentu harus berlangsung selama animasi.

/// [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]"/>
Warisan
KeyTime
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Contoh

Contoh ini menggunakan sintaks atribut XAML untuk mengatur nilai KeyTime pada beberapa jenis kelas DoubleAnimationUsingKeyFrames .

<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

Keterangan

Setiap properti KeyTime bingkai kunci menentukan kapan bingkai kunci tersebut berakhir. Ini tidak menentukan berapa lama bingkai kunci dimainkan. Jumlah waktu bingkai kunci diputar ditentukan oleh ketika bingkai kunci berakhir, ketika bingkai kunci sebelumnya berakhir, dan durasi animasi.

Menentukan KeyTime hanya dengan bilangan bulat tanpa rentang waktu apa pun karakter harfiah seperti : atau . akan menghasilkan KeyTime dari jumlah hari tersebut! Ini jarang hasil yang dimaksudkan. Biasanya Anda menentukan rentang waktu dalam detik. Dengan demikian string KeyTime biasanya mencakup nilai nol sebelumnya selama berjam-jam dan menit, bersama dengan literal : sebagai pemisah antara jam, menit, dan detik. Misalnya, untuk menentukan KeyTime lima detik, string yang benar adalah "0:0:5" ("0:0:05" setara).

Catatan tentang sintaks XAML

Anda tidak dapat mendeklarasikan KeyTime sebagai objek yang dapat dibagikan dalam ResourceDictionary.

Proyeksi dan anggota KeyTime

Jika Anda menggunakan bahasa Microsoft .NET (C# atau Microsoft Visual Basic), atau ekstensi komponen Visual C++ (C++/CX), maka KeyTime memiliki beberapa metode utilitas, dan anggota datanya TimeSpan diekspos sebagai properti baca-saja, bukan bidang.

Untuk Microsoft .NET, Durasi mengekspos TimeSpan.Parse untuk TimeSpan-nya, metode FromTimeSpan , dan operator Implisit . Ini tidak tersedia dari struktur di ekstensi komponen Visual C++ (C++/CX) tetapi Anda dapat menggunakan KeyTimeHelper.FromTimeSpan.

Jika Anda memprogram dengan C++ menggunakan Windows Runtime Template Library (WRL), maka hanya bidang anggota data TimeSpan yang ada sebagai anggota KeyTime. Kode WRL dapat mengakses FromTimeSpan seperti yang ada di kelas KeyTimeHelper .

Bidang

TimeSpan

Komponen waktu KeyTime ini.

Berlaku untuk