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
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);
}
//This doesn't work
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();
}
Does anybody has any idea? Any advice will be appreciated!
Uros
Loading
Bechir BejaouiPosted Feb 11, 2009, 5:27 PM
http://www.c-sharpcorner.com/UploadFile/yougerthen/407232008132712PM/4.aspx?ArticleID=3bc99242-c005-4560-84e5-b06c1ad10fc2
http://www.longhorncorner.com/UploadFile/yougerthen/301082009003747AM/3.aspx?ArticleID=153f6223-d74e-4137-b3ca-415dad554038
http://www.longhorncorner.com/UploadFile/yougerthen/301112009235040PM/3.aspx?ArticleID=0c82c544-7771-47be-a145-db15d56afd64