I want to animate the rectangle x position from my code behind (as the x position is only determined at the run time).
I have got the following code:
KeySpline easeOut = new KeySpline(0, 1, 0.3, 1);
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames da1 = new DoubleAnimationUsingKeyFrames();
SplineDoubleKeyFrame keyFrame1 = new SplineDoubleKeyFrame();
GeneralTransform generalTransform = rect4.TransformToVisual(this);
Point point = generalTransform.Transform(new Point());
keyFrame1.Value = point.X;
keyFrame1.KeySpline = easeOut;
da1.KeyFrames.Add(keyFrame1);
sb.Children.Add(da1);
Storyboard.SetTarget(da1, rect);
Storyboard.SetTargetProperty(da1, new PropertyPath("What is the path?"));
sb.Begin();
The thi开发者_如何学编程ng I don't know is what to put for the PropertyPath?!
If you placed it on the Canvas use this
Storyboard.SetTargetProperty(da1, new PropertyPath("(Canvas.Left)"));
I would place the code in the Xaml in Window.Resorces, give it a name x:Name="da1" and ten just simply call it in code
sb.Begin();
精彩评论