KeyTime structure

Applies to Windows and Windows Phone

Specifies when a particular key frame should take place during an animation.

Syntax


public struct KeyTime


<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>

XAML Values

days

Optional. An integer value greater than or equal to 0 that specifies the number of days.

hours

Required, even if 0. An integer value between 0 and 23 that specifies the number of hours.

minutes

Optional if only hours are desired, but must be set at least to 0 if you intend to set a seconds value. An integer value between 0 and 59 that specifies the number of minutes.

seconds

Optional if only hours/minutes are desired. An integer value between 0 and 59 that specifies the number of seconds.

fractionalSeconds

Optional. A value consisting of 1 to 7 digits of decimal precision that specifies fractional seconds.

Attributes

[Version(0x06020000)]
[WebHostHidden()]

Members

The KeyTime structure has these types of members:

Fields

The KeyTime structure has these fields.

FieldData typeDescription
TimeSpan

System.TimeSpan [.NET] | Windows::Foundation::TimeSpan [C++]

The time component of this KeyTime.

 

Methods

The KeyTime structure has these methods. It also inherits methods from the Object class.

MethodDescription
Equals(KeyTime) [C#, VB]Compares two KeyTime structures for equality.
Equals(KeyTime,KeyTime) [C#, VB]Compares two KeyTime structures for equality, as a static helper method.
Equals(Object) [C#, VB]Determines whether the specified object is equal to a KeyTime.
FromTimeSpan [C#, VB]Creates a new KeyTime, using the supplied TimeSpan.
GetHashCode [C#, VB]Gets a hash code for this object.
ToString [C#, VB]Converts a KeyTime to a String representation.

 

Operators

The KeyTime structure has these operators.

OperatorDescription
Equality Compares two KeyTime structures for equality.
Implicit Implicitly converts a TimeSpan to a KeyTime.
Inequality Compares two KeyTime structures for inequality.

 

Properties

The KeyTime structure has these properties.

PropertyAccess typeDescription

TimeSpan

Read-onlyGets the time when the key frame ends, expressed as a time relative to the beginning of the animation.

 

Remarks

Each key frame's KeyTime property specifies when that key frame ends. It does not specify how long the key frame plays. The amount of time a key frame plays is determined by when the key frame ends, when the previous key frame ended, and the animation's duration.

Specifying a KeyTime by only an integer without any time span literal characters such as : or . will result in a KeyTime of that number of days! This is seldom the intended result. Usually you specify time spans in seconds. Thus the KeyTime string typically includes preceding zero values for hours and minutes, along with the literal : as separator between hours, minutes, and seconds. For example, to specify a KeyTime of five seconds, the correct string is "0:0:5" ("0:0:05" is equivalent).

Notes on XAML syntax

You cannot declare a KeyTime as a shareable object in a ResourceDictionary.

Projection and members of KeyTime

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), or Visual C++ component extensions (C++/CX), then KeyTime has some utility methods, and its data member TimeSpan is exposed as a read-only property, not a field.

For .NET, Duration exposes TimeSpan.Parse for its TimeSpan, a FromTimeSpan method, and an Implicit operator. These aren't available from the structure in C++/CX but you can use KeyTimeHelper.FromTimeSpan.

If you are programming with C++ using the Windows Runtime Template Library (WRL), then only the data member field TimeSpan exists as a member of KeyTime. WRL code can access FromTimeSpan as it exists on the KeyTimeHelper class.

Examples

This example uses XAML attribute syntax to set KeyTime values on several types of DoubleAnimationUsingKeyFrames classes.


<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>


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Media.Animation
Windows::UI::Xaml::Media::Animation [C++]

Metadata

Windows.winmd
Platform.winmd

Assembly

System.Runtime.WindowsRuntime.UI.Xaml.dll

 

 

Show:
© 2014 Microsoft