| | |
WPF Animations
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2006
Posts: 7
Reputation:
Solved Threads: 0
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
This doesn't work
Does anybody has any idea? Any advice will be appreciated!
Uros
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)
btn_Click(object sender, RoutedEventArgs e) { LinearGradientBrush mask = new LinearGradientBrush(); GradientStop transparentStop = new GradientStop(Colors.Transparent, 0); GradientStop visibleStop = new GradientStop(Colors.Black, 0); mask.GradientStops.Add(transparentStop); mask.GradientStops.Add(visibleStop); this.OpacityMask = mask; DoubleAnimation visibleStopAnimation = new DoubleAnimation(0, 1.2, TimeSpan.FromSeconds(1.2), FillBehavior.HoldEnd); visibleStop.BeginAnimation(GradientStop.OffsetProperty, visibleStopAnimation); }
c# Syntax (Toggle Plain Text)
btn_Click(object sender, RoutedEventArgs e) { LinearGradientBrush mask = new LinearGradientBrush(); GradientStop transparentStop = new GradientStop(Colors.Transparent, 0); GradientStop visibleStop = new GradientStop(Colors.Black, 0); mask.GradientStops.Add(transparentStop); mask.GradientStops.Add(visibleStop); this.OpacityMask = mask; Storyboard story = new Storyboard(); story.Duration = TimeSpan.FromSeconds(1); DoubleAnimation visibleStopAnimation = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd); Storyboard.SetTarget(visibleStopAnimation, visibleStop); Storyboard.SetTargetProperty(visibleStopAnimation, new PropertyPath("(Offset)")); story.Children.Add(visibleStopAnimation); story.Begin(); }
Uros
![]() |
Similar Threads
- Ten Thousand Animations, Curses! (C#)
- Using timer (C#)
Other Threads in the C# Forum
- Previous Thread: Chech mark color
- Next Thread: How do I zoom to a target point and update the scrollbars in C#?
Views: 1272 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





