ColorAnimation Classe

Définition

Anime la valeur d’une propriété Color entre deux valeurs cibles à l’aide de l’interpolation linéaire sur une durée spécifiée.

public ref class ColorAnimation 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 ColorAnimation 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 ColorAnimation 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 ColorAnimation : 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 ColorAnimation : Timeline
Public NotInheritable Class ColorAnimation
Inherits Timeline
<ColorAnimation .../>
Héritage
Object Platform::Object IInspectable DependencyObject Timeline ColorAnimation
Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

L’exemple suivant montre comment utiliser ColorAnimation pour animer la couleur d’arrière-plan d’un StackPanel.

<StackPanel x:Name="myStackPanel" Background="Red"
  Loaded="Start_Animation">
  <StackPanel.Resources>
    <Storyboard x:Name="colorStoryboard">

      <!-- Animate the background color of the canvas from red to green
        over 4 seconds. -->
      <ColorAnimation Storyboard.TargetName="myStackPanel" 
        Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
        From="Red" To="Blue" Duration="0:0:4"/>

    </Storyboard>
  </StackPanel.Resources>
</StackPanel>
<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>
<StackPanel Loaded="Start_Animation">
  <StackPanel.Resources>
    <Storyboard x:Name="colorStoryboard">
      <!-- Animate the background color of the canvas from red to green
        over 4 seconds. -->
      <ColorAnimation Storyboard.TargetName="mySolidColorBrush"
        Storyboard.TargetProperty="Color" From="Red" To="Blue" Duration="0:0:4"/>
    </Storyboard>
  </StackPanel.Resources>

  <StackPanel.Background>
    <SolidColorBrush x:Name="mySolidColorBrush" Color="Red" />
  </StackPanel.Background>

</StackPanel>
// Start the animation when the object loads.
private void Start_Animation(object sender, RoutedEventArgs e)
{
    colorStoryboard.Begin();
}
' Start the animation when the object loads
Private Sub Start_Animation(ByVal sender As Object, ByVal e As EventArgs)
    colorStoryboard.Begin()
End Sub
Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"

Vous pouvez également créer explicitement solidColorBrush, le nommer et cibler directement sa propriété Color . L’exemple ci-dessous montre comment créer la même animation que la précédente, sauf qu’elle utilise le ciblage direct des propriétés.

<StackPanel Loaded="Start_Animation">
  <StackPanel.Resources>
    <Storyboard x:Name="colorStoryboard">
      <!-- Animate the background color of the canvas from red to green
        over 4 seconds. -->
      <ColorAnimation Storyboard.TargetName="mySolidColorBrush"
        Storyboard.TargetProperty="Color" From="Red" To="Blue" Duration="0:0:4"/>
    </Storyboard>
  </StackPanel.Resources>

  <StackPanel.Background>
    <SolidColorBrush x:Name="mySolidColorBrush" Color="Red" />
  </StackPanel.Background>

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

Remarques

Utilisez ColorAnimation pour animer la valeur de propriété de toute propriété de dépendance de type Color.

L’interpolation linéaire pour une couleur signifie que chacune des valeurs ARGB est traitée comme un octet et que l’interpolation est simplement une opération mathématique. Vous obtenez les meilleurs résultats de l’interpolation de couleur si au moins un des composants RVB est identique ou proche de la même valeur dans la valeur de départ et la valeur de fin.

Vous devez généralement utiliser le ciblage de propriété indirect pour cibler une sous-propriété d’un autre objet qui est la valeur d’une propriété sur la cible. Cela est dû au fait que très peu de propriétés qui affichent des informations de couleur dans les éléments d’interface utilisateur sont réellement de type Color. La plupart sont au lieu de type Brush. Pour utiliser ColorAnimation sur les éléments d’interface utilisateur, vous ciblez généralement la propriété Color d’un SolidColorBrush qui est la valeur de sous-propriété. La syntaxe est indiquée dans l’exemple XAML de la section « Exemples ». Pour plus d’informations sur le ciblage de propriété indirect et d’autres concepts d’animation de storyboard, consultez Animations storyboard ouSyntaxe de chemin de propriété.

Une ColorAnimation a généralement au moins l’une des propriétés From, By ou To définies, mais jamais les trois.

  • À partir de uniquement : L’animation progresse de la valeur spécifiée par la propriété From à la valeur de base de la propriété animée.
  • De et vers : L’animation progresse de la valeur spécifiée par la propriété From à la valeur spécifiée par la propriété To .
  • De et par : L’animation progresse de la valeur spécifiée par la propriété From à la valeur spécifiée par la somme des propriétés From et By .
  • Pour uniquement : L’animation progresse de la valeur de base de la propriété animée ou de la valeur de sortie d’une animation précédente à la valeur spécifiée par la propriété To .
  • Par uniquement : L’animation progresse de la valeur de base de la propriété animée ou de la valeur de sortie d’une animation précédente à la somme de cette valeur et de la valeur spécifiée par la propriété By .

Les propriétés From, By et To d’un ColorAnimation ne sont pas strictement une couleur. Au lieu de cela, il s’agit d’une valeur Nullable pour Color. La valeur par défaut de ceux-ci est null, et non une structure non initialisée. Cette valeur null est la façon dont le système d’animation distingue que vous n’avez pas spécifiquement défini de valeur. Le type des extensions des composants Visual C++ (C++/CX) n’est pas Nullable, par conséquent elles utilisent IReference à la place.

Constructeurs

ColorAnimation()

Initialise une nouvelle instance de la classe ColorAnimation.

Propriétés

AutoReverse

Obtient ou définit une valeur qui indique si la chronologie est lue en sens inverse après avoir effectué une itération vers l’avant.

(Hérité de Timeline)
BeginTime

Obtient ou définit l’heure à laquelle cette chronologie doit commencer.

(Hérité de Timeline)
By

Obtient ou définit la quantité totale par laquelle l’animation modifie sa valeur de départ.

ByProperty

Identifie la propriété de dépendance By .

Dispatcher

Obtient le CoreDispatcher auquel cet objet est associé. CoreDispatcher représente une fonctionnalité qui peut accéder à DependencyObject sur le thread d’interface utilisateur, même si le code est initié par un thread autre que l’interface utilisateur.

(Hérité de DependencyObject)
Duration

Obtient ou définit la durée de cette chronologie, sans prendre en compte les répétitions.

(Hérité de Timeline)
EasingFunction

Obtient ou définit la fonction d’accélération appliquée à cette animation.

EasingFunctionProperty

Identifie la propriété de dépendance EasingFunction .

EnableDependentAnimation

Obtient ou définit une valeur qui déclare si les propriétés animées considérées comme des animations dépendantes doivent être autorisées à utiliser cette déclaration d’animation.

EnableDependentAnimationProperty

Identifie la propriété de dépendance EnableDependentAnimation .

FillBehavior

Obtient ou définit une valeur qui spécifie le comportement de l’animation une fois qu’elle a atteint la fin de sa période active.

(Hérité de Timeline)
From

Obtient ou définit la valeur de départ de l’animation.

FromProperty

Identifie la propriété de dépendance From .

RepeatBehavior

Obtient ou définit le comportement à répétition de cette chronologie.

(Hérité de Timeline)
SpeedRatio

Obtient ou définit la vitesse, par rapport à son parent, à laquelle progresse pour cette chronologie.

(Hérité de Timeline)
To

Obtient ou définit la valeur de fin de l’animation.

ToProperty

Identifie la propriété de dépendance À .

Méthodes

ClearValue(DependencyProperty)

Efface la valeur locale d’une propriété de dépendance.

(Hérité de DependencyObject)
GetAnimationBaseValue(DependencyProperty)

Retourne toute valeur de base établie pour une propriété de dépendance, qui s’appliquerait dans les cas où une animation n’est pas active.

(Hérité de DependencyObject)
GetValue(DependencyProperty)

Retourne la valeur effective actuelle d’une propriété de dépendance à partir d’un DependencyObject.

(Hérité de DependencyObject)
ReadLocalValue(DependencyProperty)

Retourne la valeur locale d’une propriété de dépendance, si une valeur locale est définie.

(Hérité de DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Inscrit une fonction de notification pour écouter les modifications apportées à un DependencyProperty spécifique sur ce instance DependencyObject.

(Hérité de DependencyObject)
SetValue(DependencyProperty, Object)

Définit la valeur locale d’une propriété de dépendance sur un DependencyObject.

(Hérité de DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Annule une notification de modification précédemment inscrite en appelant RegisterPropertyChangedCallback.

(Hérité de DependencyObject)

Événements

Completed

Se produit lorsque la lecture de l’objet Storyboard est terminée.

(Hérité de Timeline)

S’applique à

Voir aussi