Examples of line-drawn animation effects implemented by WPF and those of wpf
This article provides examples to share with you the specific code for implementing line-drawn animation in WPF for your reference. The specific content is as follows:
Requirement: a straight line (not a curve) is drawn gradually on the canvas like a model stroke. However, the premise is that it is implemented using background code instead of the WPF tag.
Effect:
Code:
///// Interaction logic of 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 );}}