共用方式為


ColorAnimationUsingKeyFrames 類別

定義

沿著一組主要畫面格產生 Color 屬性的值。

public ref class ColorAnimationUsingKeyFrames sealed : Timeline
/// [Microsoft.UI.Xaml.Markup.ContentProperty(Name="KeyFrames")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ColorAnimationUsingKeyFrames final : Timeline
[Microsoft.UI.Xaml.Markup.ContentProperty(Name="KeyFrames")]
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ColorAnimationUsingKeyFrames : Timeline
Public NotInheritable Class ColorAnimationUsingKeyFrames
Inherits Timeline
<ColorAnimationUsingKeyFrames ...>
  oneOrMoreColorKeyFrames
</ColorAnimationUsingKeyFrames>
繼承
Object Platform::Object IInspectable DependencyObject Timeline ColorAnimationUsingKeyFrames
屬性

範例

下列範例會使用 ColorAnimationUsingKeyFrames 類別,以動畫顯示StackPanelBackground屬性。 這個動畫會以下列方式使用三個主要畫面格:

  1. 在前兩秒, LinearColorKeyFrame 會逐漸將色彩從綠色變更為紅色。 線性主要畫面格,例如 LinearColorKeyFrame ,會在值之間建立順暢的線性轉換。
  2. 在下半秒結束時, DiscreteColorKeyFrame 會快速將色彩從紅色變更為黃色。 DiscreteColorKeyFrame之類的離散主要畫面格會建立值之間的突然變更;動畫會快速發生,而且值之間完全沒有插補。
  3. 在最後兩秒期間, SplineColorKeyFrame 會再次變更色彩,這次從黃色回到綠色。 SplineColorKeyFrame之類的曲線主要畫面格會根據KeySpline屬性的值,在值之間建立變數轉換。 KeySpline提供一種方式來改變動畫持續時間期間與值之間的關聯性,特別是關聯性可能是難以使用個別主要畫面格產生的曲線。 在此範例中,色彩變更一開始速度緩慢,然後在接近時間區段結尾時會以指數方式加速。
<StackPanel x:Name="myStackPanel" Background="Red"
Loaded="Start_Animation">
    <StackPanel.Resources>
        <Storyboard x:Name="colorStoryboard">

            <ColorAnimationUsingKeyFrames Storyboard.TargetName="myStackPanel" 
      Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                
                <!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
                a smooth, linear animation between values. -->
                <LinearColorKeyFrame Value="Blue" KeyTime="00:00:02" />

                <!-- In the next half second, go to yellow. DiscreteColorKeyFrame creates a 
                sudden jump between values. -->
                <DiscreteColorKeyFrame Value="Yellow" KeyTime="00:00:2.5" />

                <!-- In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame 
                creates a variable transition between values depending on the KeySpline property. In this example,
                the animation starts off slow but toward the end of the time segment, it speeds up exponentially.-->
                <SplineColorKeyFrame Value="Green" KeyTime="00:00:4.5" KeySpline="0.6,0.0 0.9,0.00" />

            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </StackPanel.Resources>
</StackPanel>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
    colorStoryboard.Begin();
}

建構函式

ColorAnimationUsingKeyFrames()

初始化 ColorAnimationUsingKeyFrames 類別的新實例。

屬性

AutoReverse

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

(繼承來源 Timeline)
BeginTime

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

(繼承來源 Timeline)
Dispatcher

一律會在 null Windows 應用程式 SDK應用程式中傳回。 請改用 DispatcherQueue

(繼承來源 DependencyObject)
DispatcherQueue

DispatcherQueue取得與這個 物件相關聯的 。 DispatcherQueue表示即使程式碼是由非 UI 執行緒起始,也可以存取 DependencyObject UI 執行緒上的 。

(繼承來源 DependencyObject)
Duration

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

(繼承來源 Timeline)
EnableDependentAnimation

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

EnableDependentAnimationProperty

識別 EnableDependentAnimation 相依性屬性。

FillBehavior

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

(繼承來源 Timeline)
KeyFrames

取得定義動畫的 ColorKeyFrame 物件集合。

RepeatBehavior

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

(繼承來源 Timeline)
SpeedRatio

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

(繼承來源 Timeline)

方法

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)

適用於

另請參閱