WPF Storyboard works well, except for the first time it runs. Why?
Posted
by sofri
on Stack Overflow
See other posts from Stack Overflow
or by sofri
Published on 2010-06-14T08:47:05Z
Indexed on
2010/06/14
8:52 UTC
Read the original article
Hit count: 346
wpf
|wpf-storyboard
Hi, I'm doing a Surface Application. And there I have something like a bulletin board where little cards with news on it are pinned on. On click they shall fly out of the board and scale bigger. My storyboard works well, except for the first time it runs. It's not a smooth animation then but it scales to its final size immediately and it's the same with the orientation-property. Just the center-property seems to behave correctly.
This is an example for one of my Storyboards doing that:
Storyboard stb = new Storyboard();
PointAnimation moveCenter = new PointAnimation();
DoubleAnimationUsingKeyFrames changeWidth = new DoubleAnimationUsingKeyFrames();
DoubleAnimationUsingKeyFrames changeHeight = new DoubleAnimationUsingKeyFrames();
DoubleAnimationUsingKeyFrames changeOrientation = new DoubleAnimationUsingKeyFrames();
moveCenter.From = News1.ActualCenter;
moveCenter.To = new Point(250, 400);
moveCenter.Duration = new Duration(TimeSpan.FromSeconds(1.0));
moveCenter.FillBehavior = FillBehavior.Stop;
stb.Children.Add(moveCenter);
Storyboard.SetTarget(moveCenter, News1);
Storyboard.SetTargetProperty(moveCenter, new PropertyPath(ScatterViewItem.CenterProperty));
changeWidth.Duration = TimeSpan.FromSeconds(1);
changeWidth.KeyFrames.Add(new EasingDoubleKeyFrame(266, KeyTime.FromTimeSpan(new System.TimeSpan(0, 0, 1))));
changeWidth.FillBehavior = FillBehavior.Stop;
stb.Children.Add(changeWidth);
Storyboard.SetTarget(changeWidth, News1);
Storyboard.SetTargetProperty(changeWidth, new PropertyPath(FrameworkElement.WidthProperty));
changeHeight.Duration = TimeSpan.FromSeconds(1);
changeHeight.KeyFrames.Add(new EasingDoubleKeyFrame(400, KeyTime.FromTimeSpan(new System.TimeSpan(0, 0, 1))));
changeHeight.FillBehavior = FillBehavior.Stop;
stb.Children.Add(changeHeight);
Storyboard.SetTarget(changeHeight, News1);
Storyboard.SetTargetProperty(changeHeight, new PropertyPath(FrameworkElement.HeightProperty));
changeOrientation.Duration = TimeSpan.FromSeconds(1);
changeOrientation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(new System.TimeSpan(0, 0, 1))));
changeOrientation.FillBehavior = FillBehavior.Stop;
stb.Children.Add(changeOrientation);
Storyboard.SetTarget(changeOrientation, News1);
Storyboard.SetTargetProperty(changeOrientation, new PropertyPath(ScatterViewItem.OrientationProperty));
stb.Begin(this);
News1.Center = new Point(250, 400);
News1.Orientation = 0;
News1.Width = 266;
News1.Height = 400;
Pin1.Visibility = Visibility.Collapsed;
news1IsOutside = true;
Scroll1.IsEnabled = true;
What's wrong with it?
© Stack Overflow or respective owner