WPF实现画线动画效果
程序员文章站
2022-04-29 12:47:29
本文实例为大家分享了wpf实现画线动画的具体代码,供大家参考,具体内容如下
需求:一条直线(不是曲线),模范笔画一样在画布上逐渐画出来。但前提是,用后台代码实现,并非wp...
本文实例为大家分享了wpf实现画线动画的具体代码,供大家参考,具体内容如下
需求:一条直线(不是曲线),模范笔画一样在画布上逐渐画出来。但前提是,用后台代码实现,并非wpf标签
效果:
上代码:
/// <summary> /// window2.xaml 的交互逻辑 /// </summary> public partial class window2 : window { public window2() { initializecomponent(); var canvas = new canvas(); content = canvas; var points = new list<point>() { new point(10, 10), new point(90, 90), new point(60, 10), new point(250, 90), new point(10, 10) }; var sb = new storyboard(); for (int i = 0; i < points.count - 1; i++) { var linegeometry = new linegeometry(points[i], points[i]); var path = new path() { stroke = brushes.black, strokethickness = 2, data = linegeometry }; canvas.children.add(path); var animation = new pointanimation(points[i], points[i + 1], new duration(timespan.frommilliseconds(1000))) { begintime = timespan.frommilliseconds(i * 1010) }; sb.children.add(animation); registername("geometry" + i, linegeometry); storyboard.settargetname(animation, "geometry" + i); storyboard.settargetproperty(animation, new propertypath(linegeometry.endpointproperty)); } mousedown += (s, e) => sb.begin(this); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。