Guest User

Untitled

a guest
Jan 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // This is the animation method, it is called from the
  2. // SelectionChanged handler in the behavior passing the
  3. // AssociatedObject as the ComboBox parameter.
  4. public void AnimateComboBox(ComboBox cbo)
  5. {
  6. LinearGradientBrush myBrush = new LinearGradientBrush();
  7. myBrush = (cbo.BorderBrush as LinearGradientBrush);
  8.  
  9. Storyboard sb = new Storyboard();
  10. sb.Duration = new Duration(TimeSpan.FromMilliseconds(3000));
  11.  
  12. //have to animate each gradient stop
  13. foreach(GradientStop s in myBrush.GradientStops)
  14. {
  15. ColorAnimation anim = new ColorAnimation();
  16. anim.To = Colors.Red;
  17. anim.Duration = new Duration(TimeSpan.FromSeconds(0.5));
  18. //auto-reverse and repeat for pulsation
  19. anim.AutoReverse = true;
  20. anim.RepeatBehavior = RepeatBehavior.Forever;
  21.  
  22. Storyboard.SetTarget(anim, s);
  23. Storyboard.SetTargetProperty(anim,
  24. new PropertyPath(GradientStop.ColorProperty));
  25.  
  26. sb.Children.Add(anim);
  27. }
  28.  
  29. sb.Begin();
  30. }
  31.  
  32. <ComboBox > <!-- leaving out ItemsSource and so-forth for brevity -->
  33. <i:Interaction.Behaviors>
  34. <vms:AnimateSelectionChangedBehavior/>
  35. </i:Interaction.Behaviors>
  36. </ComboBox>
  37. <ComboBox>
  38. <!-- this one does not have the behavior, but its border
  39. changes with the other one. -->
  40. </ComboBox>
Add Comment
Please, Sign In to add comment