Bonsoir tous le monde,
je vient de débuté a faire des animations avec wpf, je veux faire une animation qui fait changer la couleur d'un rectangle, je n'arrive pas a trouvé la propriété approprier, voici mon code:
Code : 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 public partial class MainWindow : Window
    {
        private Storyboard myStoryboard;
 
        public MainWindow()
        {
            InitializeComponent();
 
            StackPanel myPanel = new StackPanel();
            myPanel.Margin = new Thickness(10);
 
            Rectangle myRectangle = new Rectangle();
            myRectangle.Name = "myRectangle";
            this.RegisterName(myRectangle.Name, myRectangle);
            myRectangle.Width = 100;
            myRectangle.Height = 100;
            myRectangle.Fill = Brushes.Green;
 
            ColorAnimation myDoubleAnimation = new ColorAnimation();
            myDoubleAnimation.From = Colors.Blue ;
            myDoubleAnimation.To = Colors.Yellow;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
            myDoubleAnimation.AutoReverse = true;
            myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
 
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTargetName(myDoubleAnimation, myRectangle.Name);
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.ColorProperty));
 
            // Use the Loaded event to start the Storyboard.
            myRectangle.Loaded += new RoutedEventHandler(myRectangleLoaded);
            myPanel.Children.Add(myRectangle);
            this.Content = myPanel;
        }
 
        private void myRectangleLoaded(object sender, RoutedEventArgs e)
        {
            myStoryboard.Begin(this);
        }
    }

Merci d'avance.