title: How to draw lines with mouse in C#
body: <p>Im currently trying to make a pragram in visual studio WPF form, that draws lines using mouse like in paint. 
  Currently it is drawing the same old line and continues drawing it but i want to     draw a new line each time i press the left mouse button    . Here's the <strong>MainWindows.xaml.cs</strong> code and what it looks like:</p>
  
  <pre><code>namespace DrawingLines
  {
  
  public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private PathFigure _pathFigure = new PathFigure();
      PathFigureCollection _pathCollection = new PathFigureCollection();
      PathSegmentCollection _segments = new PathSegmentCollection();
      private PathGeometry _pathGeometry = new PathGeometry();
  
      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          _pathFigure.Segments = _segments;
          _pathCollection.Add(_pathFigure);
          _pathGeometry.Figures = _pathCollection;
          myPath.Data = _pathGeometry;
      }
  
      private void Window_MouseMove(object sender, MouseEventArgs e)
      {
          if (e.LeftButton == MouseButtonState.Pressed)
          {
              LineSegment segment = new LineSegment();
              segment.Point = e.GetPosition(this);
              _pathFigure.Segments.Add(segment);
          }
  
      }
  
      private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
      {
          _pathFigure.StartPoint = e.GetPosition(this);
      }
  
      //private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
      //{
  
      //}
  
      private void button1_Click(object sender, RoutedEventArgs e)
      {
          this.Close();
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And here's the <strong>MainWindow.xmal</strong> code: </p>
  
  <pre><code>&lt;Window x:Class="DrawingLines.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Joonistamine" Height="350" Width="525" Loaded="Window_Loaded" MouseMove="Window_MouseMove" MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseRightButtonDown="Window_MouseRightButtonDown"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="53*" /&gt;
          &lt;RowDefinition Height="258*" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="124*" /&gt;
          &lt;ColumnDefinition Width="379*" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Path Stroke="Black" StrokeThickness="1" Name="myPath" Grid.ColumnSpan="2" Grid.RowSpan="2" /&gt;
      &lt;Button Content="Exit" Height="25" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="46" Click="button1_Click" BorderBrush="Red" Foreground="#FFFF1A1A" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>What am i doing wrong?</p>