public async Task DrawLine(CanvasEdge canvasEdge) { await Application.Current.Dispatcher.InvokeAsync(() => { var line = new Line() { X1 = canvasEdge.Start.X + (this.Canvas.Width / 2), Y1 = canvasEdge.Start.Y + (this.Canvas.Height / 2), X2 = canvasEdge.End.X + (this.Canvas.Width / 2), Y2 = canvasEdge.End.Y + (this.Canvas.Height / 2), Stroke = Brushes.DarkViolet, }; this.LinesOnCanvas.TryAdd(canvasEdge.PrimaryEdge, line); var lineAnimationX = new DoubleAnimation { From = line.X1, To = line.X2, Duration = TimeSpan.FromMilliseconds(this.AnimationDuration) }; var lineAnimationY = new DoubleAnimation { From = line.Y1, To = line.Y2, Duration = TimeSpan.FromMilliseconds(this.AnimationDuration), }; this.Canvas.Children.Add(line); line.BeginAnimation(Line.X2Property, lineAnimationX); line.BeginAnimation(Line.Y2Property, lineAnimationY); }); }
public async Task DrawLine(IEnumerable <Vertex> vertices) { var v = vertices.ToList(); var first = v.FirstOrDefault(); var last = v.LastOrDefault(); for (var i = 0; i < v.Count - 1; i++) { var canvasEdge = new CanvasEdge(new Edge(v[i], v[i + 1]), this.Zoom); await this.DrawLine(canvasEdge); } await this.DrawLine(new CanvasEdge(new Edge(last, first), this.Zoom)); }