title: Animating a line while drawing in wpf
body: <p>XAML</p>
  
  <pre><code>&lt;Canvas Name="canvas" MouseDown="canvas_MouseDown" MouseUp="canvas_MouseUp" Background="White" MouseMove="canvas_MouseMove" /&gt;
  </code></pre>
  
  <p>C#</p>
  
  <pre><code>Line AnimationLine;
  Point P1;
  private void canvas_MouseDown(object sender, MouseButtonEventArgs e)
  {
      P1 = e.GetPosition(canvas);
      AnimationLine = new Line() { Stroke = new SolidColorBrush { Color = Colors.Blue },StrokeThickness = 3};
      AnimationLine.X1 = P1.X;
      AnimationLine.Y1 = P1.Y;
      canvas.Children.Add(AnimationLine);
  }
  
  
  private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
  {
      var P2 = e.GetPosition(canvas);
      canvas.Children.Remove(AnimationLine);
      //AnimationLine = new Line();
      canvas.Children.Add
        (new Line()
        {
            X1 = P1.X,
            Y1 = P1.Y,
            X2 = P2.X,
            Y2 = P2.Y,
            StrokeThickness = 3,
            Stroke = new SolidColorBrush { Color = Colors.Blue }
        });
  }
  
  private void canvas_MouseMove(object sender, MouseEventArgs e)
  {
      if(e.LeftButton == MouseButtonState.Pressed)
      { 
         var P2 = e.GetPosition(canvas);
         AnimationLine.X2 = P2.X;
         AnimationLine.Y2 = P2.Y;
      }
  }
  </code></pre>
  
  <p>i am trying to draw a line first point assigned on mouse down, second point assigned on mouse up and thats when the line gets drawn, but when dragging i want to show the Animation line, animation line which is like a real time guide line.</p>
  
  <p>in order to get it i want to draw a line just like in microsoft paint.</p>
  
  <p>i just wrote the above and it works great, but is this really the way to do it? any built in functionalities that could help?</p>