资 源 简 介
C# wpf 创建简单形状动画的例子,启动动画、停止动画、暂停动画、继续动画、加速动画。创建动画
Rectangle MyRectangle = new Rectangle();
MyRectangle.Width = 50;
MyRectangle.Height = 20;
MyRectangle.Margin = new Thickness(10, 50, 0, 0);
MyRectangle.Fill = new LinearGradientBrush(
Color.FromArgb(255, 0, 255, 255), Color.FromArgb(255, 0, 0, 255), 0);
MyRectangle.HorizontalAlignment = HorizontalAlignment.Left;
this.canvas1.Children.Add(MyRectangle);
this.RegisterName("MyRectangle", MyRectangle);
DoubleAnimation MyAnimation =
new DoubleAnimation(100, 380, new Duration(TimeSpan.FromSeconds(5)));
Storyboard.SetTargetName(MyAnimation, "MyRectangle");
Storyboard.SetTargetProperty(MyAnimation,
new PropertyPath(Rectangle.WidthProperty));
MyStoryboard = new Storyboard();
MyStoryboard.Children.Add(MyAnimation);
动画效果请参见下图所示,源代码请单击下载按钮下载。