本篇文章給大家分享的是有關(guān)WPF中怎么實(shí)現(xiàn)畫線動(dòng)畫效果,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
上代碼:
////// 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中怎么實(shí)現(xiàn)畫線動(dòng)畫效果,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。