WPF Animations

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 7
Reputation: Uros Bregar is an unknown quantity at this point 
Solved Threads: 0
Uros Bregar Uros Bregar is offline Offline
Newbie Poster

WPF Animations

 
0
  #1
Feb 6th, 2009
Hi

I am trying to create and start an animation in code instead of using xaml. When I use the Storyboard object(second example) nothing happens(There are no visible results of the animation), if I set animation's properties and start it without using the Storyboard object everything works normaly(first example). Below is the sample code which is put in the event handler for a button which is on the UserControl.

This works normaly
  1. btn_Click(object sender, RoutedEventArgs e)
  2. {
  3. LinearGradientBrush mask = new LinearGradientBrush();
  4.  
  5. GradientStop transparentStop = new GradientStop(Colors.Transparent, 0);
  6. GradientStop visibleStop = new GradientStop(Colors.Black, 0);
  7.  
  8. mask.GradientStops.Add(transparentStop);
  9. mask.GradientStops.Add(visibleStop);
  10.  
  11. this.OpacityMask = mask;
  12.  
  13. DoubleAnimation visibleStopAnimation = new DoubleAnimation(0, 1.2, TimeSpan.FromSeconds(1.2), FillBehavior.HoldEnd);
  14. visibleStop.BeginAnimation(GradientStop.OffsetProperty, visibleStopAnimation);
  15. }
This doesn't work
  1. btn_Click(object sender, RoutedEventArgs e)
  2. {
  3. LinearGradientBrush mask = new LinearGradientBrush();
  4. GradientStop transparentStop = new GradientStop(Colors.Transparent, 0);
  5. GradientStop visibleStop = new GradientStop(Colors.Black, 0);
  6. mask.GradientStops.Add(transparentStop);
  7. mask.GradientStops.Add(visibleStop);
  8. this.OpacityMask = mask;
  9.  
  10. Storyboard story = new Storyboard();
  11. story.Duration = TimeSpan.FromSeconds(1);
  12. DoubleAnimation visibleStopAnimation = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd);
  13. Storyboard.SetTarget(visibleStopAnimation, visibleStop);
  14. Storyboard.SetTargetProperty(visibleStopAnimation, new PropertyPath("(Offset)"));
  15. story.Children.Add(visibleStopAnimation);
  16. story.Begin();
  17. }
Does anybody has any idea? Any advice will be appreciated!
Uros
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC