title: WPF How to check if in canvas is empty spaces
body: <p>I am adding rectangles on a Canvas using Random because I don't know the width and height.</p>
  
  <p>Code</p>
  
  <pre><code>  HProDataContext db = new HProDataContext();
  
          var RoomX = (from d in db.rooms select d.sizex).ToList();
          var RoomY = (from d in db.rooms select d.sizey).ToList();
          var random = new Random();
          for (int i = 0; i &lt; RoomX.Count; i++)
          {
  
              RoomX[i] = (Convert.ToDouble(RoomX[i]) * 10).ToString();
              RoomY[i] = (Convert.ToDouble(RoomY[i]) * 10).ToString();
  
              var rectangle = new Rectangle()
              {
                  Stroke = Brushes.Black,
                  Fill = Brushes.SkyBlue,
                  Width = Convert.ToDouble(RoomX[i]),
                  Height = Convert.ToDouble(RoomY[i]),
                  Margin = new Thickness(
                      left: random.NextDouble() * 300,
                      top: random.NextDouble() * 150,
                      right: 0,
                      bottom: 0),
                  HorizontalAlignment = HorizontalAlignment.Left,
                  VerticalAlignment = VerticalAlignment.Top
              };
              mainCanvas.Children.Add(rectangle);
          }
      }
  </code></pre>
  
  <p>It works good, but some rectangles are drawing over another rectangles.<br>
  How to draw rectangles there where is empty space?</p>
  
  <p><img src="https://i.stack.imgur.com/3ToZn.jpg" alt="enter image description here"></p>