title: Why I can't remove image in canvas WPF C#?
body: <p>I have my class in Anobject.cs file:</p>
  <pre><code>public class AnObject
  {
      public string Name { get; set; }
      public int? X { get; set; }
      public int? Y { get; set; }
      public AnObject(string name = null, int? x = null, int? y = null)
      {
          this.Name = name;
          this.X = x;
          this.Y = y;
      }
  }
  </code></pre>
  <p>And my page RolePlay.xaml.cs:</p>
  <pre><code>readonly AnObject[,] allObjects = new AnObject[50,38];
      private void RolePlayPage_Loaded(object sender, RoutedEventArgs e)
      {
          AnObject anObject = new AnObject();
          for (int i = 0; i &lt; 50; i++)
          {
              for (int j = 0; j &lt; 38; j++)
              {
                  allObjects[i, j] = anObject;
              }
          }
  
          List&lt;string&gt; lines = File.ReadAllLines(@&quot;myfile.txt&quot;).ToList();
          foreach (string line in lines)
          {
              string[] data = line.Split(' ');
              string data0 = data[0];
              int data1 = int.Parse(data[1]);
              int data2 = int.Parse(data[2]);
  
              anObject = new AnObject(data0, data1, data2);
  
              allObjects[data1, data2] = anObject;
          }
      }
  </code></pre>
  <p>My creating image in canvas method:</p>
  <pre><code>    private void UpdateAllObjects()
      {
          foreach (AnObject obj in allObjects)
          {
              if (obj.Name != null)
              {
                  Image objPic = new Image
                  {
                      Name = obj.Name + obj.X.ToString() + obj.Y.ToString(),
                      Width = 20,
                      Height = 20,
                      Source = new BitmapImage(new Uri($@&quot;Objects\{obj.Name}.png&quot;, UriKind.Relative))
                  };
                  Canvas.SetLeft(objPic, (double)(obj.X * 20));
                  Canvas.SetTop(objPic, (double)(obj.Y * 20));
                  RolePlayCanvas.Children.Add(objPic);
              }
          }
      }
  </code></pre>
  <p>My problems are here in my removePic method:</p>
  <pre><code>if (allObjects[x, y].Name != null)
  {
      Image picName = (Image)FindName(allObjects[x, y].Name + allObjects[x, y].X.ToString() + allObjects[x, y].Y.ToString());
      RolePlayCanvas.Children.Remove(picName);
      // Canvas.SetLeft(picName, 0);
      allObjects[x, y].Name = null;
  }
  </code></pre>
  <p>why the picName isn't removed from canvas?
  Try to excutes this &quot;Canvas.SetLeft(picName, 0);&quot; line will occur error: System.ArgumentNullException: 'Value cannot be null'.</p>