title: Remove 2 different object types from canvas with mouseDown
body: <p>So i've got 2 types of object to place on my canvas: Rectangles and Textboxes. <strong>My problem is as follow</strong>: I need to remove with Mousedown the rectangles and textboxes like an eraser. I can remove only a rectangle if I only place rectangles on my screen, I can remove only a textbox if I only place a textbox on my screen. But I need to remove them both on my screen with <code>Mousedown</code> (mouse) so for <strong>example</strong>: on my screen they are 2 rectangles and 1 <code>textbox</code>, I click on them and got the follow <strong>error</strong>: 
  Cannot convert an object of type System.Windows.Controls.TextBox into a type of System.Windows.Shapes.Rectangle</p>
  
  <p>I know it's a casting problem, but I tried so many things. </p>
  
  <p>This is my code for the moment:</p>
  
  <pre><code>class Eraser
  {
      private Label status;
      private List&lt;Rectangle&gt; kaders;
      private List&lt;TextBox&gt; textboxen;
      private Canvas window;
  
      public Eraser(Canvas win, Label status)
      {
          this.status = status;
          this.window = win;
          //Application.Current.MainWindow.Cursor  = new Cursor(AppDomain.CurrentDomain.BaseDirectory + @"../../Icons/eraser.cur");
          //Mouse.OverrideCursor = newCursor;
          //Mouse.OverrideCursor = Application.Current.MainWindow.Cursor;
          textboxen = new List&lt;TextBox&gt;();
          kaders = new List&lt;Rectangle&gt;();
          foreach (Object element in win.Children)
          {
              if (element is Rectangle)
              {
                  Mouse.RemoveMouseDownHandler(window, item_Mousedown);
                  verzamelKaders();
              }
              else if (element is TextBox)
              {
                  Mouse.RemoveMouseDownHandler(window, Element_Mousedown);
                  verzamelTextboxen();
              }
          }
  
      }
      private void verzamelKaders()
      {
          Mouse.RemoveMouseDownHandler(window, item_Mousedown);
  
          foreach (Rectangle element in window.Children)
          {
              if (element.GetType() == typeof(Rectangle))
              {
                  Mouse.RemoveMouseDownHandler(window, item_Mousedown);
                  kaders.Add(element);
                  element.MouseDown += new MouseButtonEventHandler(Element_Mousedown);
              }
              else
              {
                  element.MouseDown += new MouseButtonEventHandler(item_Mousedown);
              }
          }
  
      }
      private void verzamelTextboxen()
      {
  
          Mouse.RemoveMouseDownHandler(window, Element_Mousedown);
  
  
          foreach (TextBox item in window.Children)
          {
              if (item.GetType() == typeof(TextBox))
              {
                  Mouse.RemoveMouseDownHandler(window, Element_Mousedown);
                  textboxen.Add(item);
                  item.PreviewMouseDown += new MouseButtonEventHandler(item_Mousedown);
              }
              else
              {
                  item.MouseDown += new MouseButtonEventHandler(Element_Mousedown);
              }
  
          }
  
      }
      private void Element_Mousedown(object sender, MouseButtonEventArgs e)
      {
          Mouse.RemoveMouseDownHandler(window, item_Mousedown);
          Rectangle removekader = new Rectangle();
          removekader = (Rectangle)sender;
          window.Children.Remove(removekader);
  
      }
      private void item_Mousedown(object sender, MouseButtonEventArgs e)
      {
  
          Mouse.RemoveMouseDownHandler(window, Element_Mousedown);
          TextBox removeTextbox = new TextBox();
          removeTextbox = (TextBox)sender;
          window.Children.Remove(removeTextbox);
  
      }
  </code></pre>
  
  <p>}</p>