title: Remove Line from Canvas in WPF
body: <p>Hy guys, I'm trying to delete a Line previously created by button pressed. I also want the line to be deleted by button pressed. There are a large number of lines on my canvas, so I've tried selecting it by name to delete it but I failed. Also I tried by Uid and did not work. </p>
  
  <p>Here is the code for the line created:</p>
  
  <pre><code> private void butonAdaugare_Click(object sender, RoutedEventArgs e)
      {
  
          Linie1.Y2 = Linie1.Y2 + 21;
          Linie2.Y2 = Linie2.Y2 + 21;
          Linie3.Y2 = Linie3.Y2 + 21;
          Linie4.Y2 = Linie4.Y2 + 21;
  
          Line linienoua = new Line();
          linienoua.Uid = "LinieNoua" + i;
          linienoua.X1 = 10;
          linienoua.Y1 = Linie4.Y2;
          linienoua.X2 = 670;
          linienoua.Y2 = Linie4.Y2;
          linienoua.Visibility = System.Windows.Visibility.Visible;
          linienoua.Stroke = System.Windows.Media.Brushes.Black;
          linienoua.StrokeThickness = 1;
          canvas1.Children.Add(linienoua);
  
          i++;
  
          foreach (Line l in canvas1.Children.OfType&lt;Line&gt;())
          {
              for (int j = 2; j &lt; 15; j++)
              {
                  if (l.Name == "V" + j)
                      l.Y2 = l.Y2 + 21;
              }
          } 
      }
  </code></pre>
  
  <p>And this is the removal part by Uid:</p>
  
  <pre><code>    private void butonStergere_Click(object sender, RoutedEventArgs e)
      {
  
          if (Linie1.Y2 &gt; 101 &amp;&amp; Linie2.Y2 &gt; 101 &amp;&amp; Linie3.Y2 &gt; 101 &amp;&amp; Linie4.Y2 &gt; 101)
          {
              Linie1.Y2 = Linie1.Y2 - 21;
              Linie2.Y2 = Linie2.Y2 - 21;
              Linie3.Y2 = Linie3.Y2 - 21;
              Linie4.Y2 = Linie4.Y2 - 21;
          }
  
  
          foreach (Line l in canvas1.Children.OfType&lt;Line&gt;())
          {
              if (l.Uid == "LinieNoua" + i)
                  canvas1.Children.Remove(l);
  
              for (int j = 2; j &lt; 15; j++)
              {
                  if (l.Name == "V" + j &amp;&amp; l.Y2 &gt; 91)
                      l.Y2 = l.Y2 - 21;
              }
          }
  
          i--;           
      } 
  </code></pre>
  
  <p>Any thoughts on this ? </p>