Salut,
Voilà je débute en WPF et SilverLight et là j'essaye de réaliser une anim sur la couleur d'une entité au MouseEnter...
Comme je voudrai rester dynamique je ne code rien en XAML et génère mon storyboard côté code behind... Et je n'arrive pas à obtenir un effet voici le code:
dans l'initialize :La propriété de mon objet
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Storyboard oStory = new Storyboard(); ColorAnimation oColorAnim = new ColorAnimation(); oColorAnim.To = Colors.Green; oColorAnim.Duration = new Duration(TimeSpan.FromSeconds(5)); oStory.Children.Add(oColorAnim); Storyboard.SetTarget(oColorAnim, this); DependencyProperty oProp = DependencyProperty.Register("CouleurBordure", typeof(Color), typeof(UCBouton), new PropertyMetadata(Colors.Blue)); Storyboard.SetTargetProperty(oColorAnim, new PropertyPath(oProp));
dans l'event :
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 public Color CouleurBordure {<div style="margin-left:40px"> get {<div style="margin-left:40px"> SolidColorBrush oBrush = (SolidColorBrush)Rect.Stroke; return oBrush.Color;</div>} set {<div style="margin-left:40px"> SolidColorBrush oBrush = (SolidColorBrush)Rect.Stroke; if (oBrush == null) {<div style="margin-left:40px"> oBrush = new SolidColorBrush(value); Rect.Stroke = oBrush;</div>} else<div style="margin-left:40px"> oBrush.Color = value;</div></div>}</div>}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 oStory.Begin();
Partager