您现在的位置是:网站首页> 编程资料编程资料
WPF实现画线动画效果_实用技巧_
2023-05-24
235人已围观
简介 WPF实现画线动画效果_实用技巧_
本文实例为大家分享了WPF实现画线动画的具体代码,供大家参考,具体内容如下
需求:一条直线(不是曲线),模范笔画一样在画布上逐渐画出来。但前提是,用后台代码实现,并非WPF标签
效果:

上代码:
////// Window2.xaml 的交互逻辑 /// public partial class Window2 : Window { public Window2() { InitializeComponent(); var canvas = new Canvas(); Content = canvas; var points = new List() { 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); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- WPF实现左右移动(晃动)动画效果_实用技巧_
- 详解在Azure上部署Asp.NET Core Web App_实用技巧_
- Asp.Net 5分钟实现网页实时监控_实用技巧_
- Asp.net MVC实现生成Excel并下载功能_实用技巧_
- .Net Core内存回收模式及性能测试对比分析_实用技巧_
- WPF水珠效果按钮组的实现教程_实用技巧_
- CefSharp v62修改方法(支持.net4.0)_实用技巧_
- asp.net core webapi 服务端配置跨域的实例_实用技巧_
- ADO.NET获取数据(DataSet)同时获取表的架构实例_实用技巧_
- ASP.NET Core 2.0 WebApi全局配置及日志实例_实用技巧_
