Bonjour,
J'essai tant bien que mal de créer une animation pour changer la couleur d'un rectangle, mais je ne trouve pas la solution.

voici mon code :

WPF
Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
<Rectangle Height="Auto" HorizontalAlignment="Stretch" Name="rectangle1" Stroke="#82FFFFFF" VerticalAlignment="Stretch" Width="Auto" RadiusX="15" RadiusY="15" Fill="#82FFFFFF" Grid.RowSpan="2" />

C#
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
private Storyboard sbColorAnim = new Storyboard();
 
...
 
private void InitColorAnimation()
        {
            ColorAnimation colorAnim = new ColorAnimation();
            colorAnim.Duration = new Duration(TimeSpan.FromMilliseconds(400));
            colorAnim.AutoReverse = true;
            colorAnim.From = Color.FromArgb(130, 255, 255, 255);
            colorAnim.To = Colors.Red;
 
            Storyboard.SetTarget(colorAnim, this.rectangle1.Fill);
            Storyboard.SetTargetProperty(colorAnim, new PropertyPath(SolidColorBrush.ColorProperty));
            this.sbColorAnim.Children.Add(colorAnim);
        }
 
...
 
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            this.rectangle1.BeginStoryboard(sbColorAnim);
        }

J'ai trouver beaucoup d'information sur le sujet, mais sans résultat.

Merci pour votre aide.