DoubleAnimation 類別

定義

使用指定Duration的線性內插補點,以動畫顯示兩個目標值之間的Double屬性值。

public ref class DoubleAnimation sealed : Timeline
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DoubleAnimation final : Timeline
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class DoubleAnimation final : Timeline
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DoubleAnimation : Timeline
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class DoubleAnimation : Timeline
Public NotInheritable Class DoubleAnimation
Inherits Timeline
<DoubleAnimation />
繼承
Object Platform::Object IInspectable DependencyObject Timeline DoubleAnimation
屬性

Windows 需求

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

範例

下列範例示範如何使用 DoubleAnimation 建立在載入後淡入和淡出檢視的矩形。

<StackPanel>
    <StackPanel.Resources>
        <Storyboard x:Name="myStoryboard">
            <DoubleAnimation
          Storyboard.TargetName="MyAnimatedRectangle"
          Storyboard.TargetProperty="Opacity"
          From="1.0" To="0.0" Duration="0:0:3"
          AutoReverse="True" RepeatBehavior="Forever" />
        </Storyboard>
    </StackPanel.Resources>

    <Rectangle Loaded="Start_Animation" x:Name="MyAnimatedRectangle"
     Width="100" Height="100" Fill="Blue" />

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

備註

使用 DoubleAnimation 以動畫顯示 屬於 Double類型之任何相依性屬性的屬性值。

有時候,您必須使用間接屬性目標,才能將目標設為目標上另一個物件的子屬性,該物件是目標上的屬性值。 例如,若要以動畫顯示UIElementRenderTransform的 X 元件,您需要參考一些中繼物件屬性值,直到間接屬性路徑的最後一個步驟真正是Double值為止,如同TranslateTransform.X的情況一樣。 本範例中 用於 Storyboard.TargetProperty 的正確字串是 「 (UIElement.RenderTransform) . (TranslateTransform.X) 」。 如需間接屬性目標和其他分鏡腳本動畫概念的詳細資訊,請參閱 分鏡腳本動畫

DoubleAnimation 通常至少有一個 FromByTo 屬性已設定,但絕不會全部設定三個屬性。

  • 僅從: 動畫會從 From 屬性所指定的值進展到要產生動畫效果之屬性的基底值。
  • From 和 To: 動畫會從 From 屬性所指定的值進展到 To 屬性所指定的值。
  • 寄件者和依據: 動畫會從 From 屬性所指定的值進展到 FromBy 屬性的總和所指定的值。
  • 僅限: 動畫會從動畫屬性的基底值或先前動畫的輸出值進展到 To 屬性所指定的值。
  • 僅限: 動畫會從要產生動畫效果的屬性基底值或先前動畫的輸出值,到該值和 By 屬性所指定的值總和。

您無法使用 DoubleAnimation 讓PointXY值產生動畫效果,因為這些屬性不是相依性屬性, (Point是結構,而且不能有相依性屬性。) 改用PointAnimation來動畫顯示具有Point值的相依性屬性。

您也可以使用 DoubleAnimation 以動畫顯示 int 值或 位元組 值。 相反地,您必須使用 ObjectAnimationUsingKeyFrames,這不會提供插補行為,因此您可能需要定義多個主要畫面格,以取得合理的平滑動畫。 沒有許多 UI 相關相依性屬性使用 int 值或 位元組 值,因此這不應該是自訂屬性以外的常見案例。

DoubleAnimation 的 FromByTo 屬性不是 Double。 相反地,這些是Double 的可為 Null 這些的預設值為 null,而不是 0。 該 Null 值是動畫系統區分您尚未特別設定值的方式。 Visual C++ 元件延伸 (C++/CX) 沒有 Nullable 型別,所以改用 IReference

建構函式

DoubleAnimation()

初始化 DoubleAnimation 類別的新實例。

屬性

AutoReverse

取得或設定值,其中該值指出時間軸是否會在完成向前反覆項目後反向播放。

(繼承來源 Timeline)
BeginTime

取得或設定這個 時間軸 應該開始的時間。

(繼承來源 Timeline)
By

取得或設定動畫變更其起始值所依據的總量。

ByProperty

識別 By 相依性屬性。

Dispatcher

取得這個 物件相關聯的 CoreDispatcherCoreDispatcher代表可在 UI 執行緒上存取DependencyObject的功能,即使程式碼是由非 UI 執行緒起始也一樣。

(繼承來源 DependencyObject)
Duration

取得或設定這個時間表播放的時間長度 (不計算重複次數)。

(繼承來源 Timeline)
EasingFunction

取得或設定套用至這個動畫的 easing 函式。

EasingFunctionProperty

識別 EasingFunction 相依性屬性。

EnableDependentAnimation

取得或設定值,這個值會宣告是否應該允許考慮相依動畫的動畫屬性使用此動畫宣告。

EnableDependentAnimationProperty

識別 EnableDependentAnimation 相依性屬性。

FillBehavior

取得或設定值,這個值會指定動畫在到達使用期間結束時的行為。

(繼承來源 Timeline)
From

取得或設定此動畫的起始值。

FromProperty

識別 From 相依性屬性。

RepeatBehavior

取得或設定這個時間軸的重複行為。

(繼承來源 Timeline)
SpeedRatio

取得或設定相對於其父系的速率,此時會進行這個 時間軸

(繼承來源 Timeline)
To

取得或設定此動畫的結束值。

ToProperty

識別 To 相依性屬性。

方法

ClearValue(DependencyProperty)

清除相依性屬性的本機值。

(繼承來源 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

傳回為相依性屬性建立的任何基底值,如果動畫未使用中,則適用此屬性。

(繼承來源 DependencyObject)
GetValue(DependencyProperty)

DependencyObject傳回相依性屬性的目前有效值。

(繼承來源 DependencyObject)
ReadLocalValue(DependencyProperty)

如果已設定本機值,則傳回相依性屬性的本機值。

(繼承來源 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

註冊通知函式,以接聽此DependencyObject實例上特定DependencyProperty的變更。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定 DependencyObject上相依性屬性的本機值。

(繼承來源 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消先前透過呼叫 RegisterPropertyChangedCallback註冊的變更通知。

(繼承來源 DependencyObject)

事件

Completed

發生于 Storyboard 物件已完成播放時。

(繼承來源 Timeline)

適用於

另請參閱