询问者
怎样以动画的效果画出贝塞尔曲线?

问题
全部回复
-
你好,
这里有篇博客是关于制作贝塞尔曲线动画,虽然是silverlight的,但是你可以参考下:
http://www.cnblogs.com/Aimeast/archive/2011/09/18/2180474.html
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Lisa,基于您给出的参考,我写了我的C#代码,调试许久,可是页面上什么也没有发生。郁闷。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace MyFirstWpfApplication
{
/// <summary>
/// Interaction logic for Page4bezier.xaml
/// </summary>
public partial class Page4bezier : Page
{
Storyboard storyboard;public Page4bezier()
{
InitializeComponent();storyboard = new Storyboard();
InitializeBezierAnimation();
Loaded += (s, e) => storyboard.Begin();
}private void InitializeBezierAnimation()
{
Canvas bezierCanvas = new Canvas();Point ptStart = new Point(35, 80);
Point ptPoint1 = new Point(120, 80);
Point ptPoint2 = new Point(50, 150);
Point ptEnding = new Point(135, 150);PathGeometry pg = new PathGeometry();
PathFigure pf = new PathFigure();
pf.StartPoint = new Point(ptStart.X, ptStart.Y);
BezierSegment bs = new BezierSegment(new Point(ptStart.X, ptStart.Y), new Point(ptStart.X, ptStart.Y), new Point(ptStart.X, ptStart.Y), true);
pf.Segments.Add(bs);
pg.Figures.Add(pf);Path path = new Path()
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Data = pg
};bezierCanvas.Children.Add(path);
PointAnimation point1Animation = new PointAnimation(new Point(ptStart.X, ptStart.Y), new Point(ptPoint1.X, ptPoint1.Y), new Duration(TimeSpan.FromMilliseconds(1000)));
PointAnimation point2Animation = new PointAnimation(new Point(ptPoint1.X, ptPoint1.Y), new Point(ptPoint2.X, ptPoint2.Y), new Duration(TimeSpan.FromMilliseconds(1000)));
PointAnimation point3Animation = new PointAnimation(new Point(ptPoint2.X, ptPoint2.Y), new Point(ptEnding.X, ptEnding.Y), new Duration(TimeSpan.FromMilliseconds(1000)));storyboard.Children.Add(point1Animation);
storyboard.Children.Add(point2Animation);
storyboard.Children.Add(point3Animation);Storyboard.SetTarget(point1Animation, path);
Storyboard.SetTarget(point2Animation, path);
Storyboard.SetTarget(point3Animation, path);Storyboard.SetTargetProperty(point1Animation, new PropertyPath(BezierSegment.Point1Property));
Storyboard.SetTargetProperty(point2Animation, new PropertyPath(BezierSegment.Point2Property));
Storyboard.SetTargetProperty(point3Animation, new PropertyPath(BezierSegment.Point3Property));Line ln = new Line();
ln.X1 = ln.Y1 = 450;
ln.X2 = ln.Y2 = 340;
ln.Stroke = Brushes.Blue;bezierCanvas.Children.Add(ln);
this.Content = bezierCanvas;
}
}
}