943,707 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3977
  • C# RSS
Feb 6th, 2009
0

WPF Animations

Expand Post »
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
c# Syntax (Toggle Plain Text)
  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
c# Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Uros Bregar is offline Offline
7 posts
since Jul 2006
Aug 16th, 2010
0
Re: WPF Animations
I hit this problem about a month ago and gave up on it until today when I discovered NameScope. When I used a NameScope and used SetTargetName instead, it worked. Here is the article that showed me how to use NameScope: http://msdn.microsoft.com/en-us/library/ms746609.aspx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Stuporman is offline Offline
1 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: show new form on load of the main form
Next Thread in C# Forum Timeline: Creating a code based on the evaluation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC