0

I´m using this code:

canvas.Children.Add(rect);
Canvas.SetTop(rect, (100 - prof) + (j * height));
Canvas.SetLeft(rect, (100 + prof) + (k * widht));

to draw many rectangles inside a previous drawn rectangle that is inside a canvas.

I need to delete/clear this rectangles.

I´ve tried

  canvas.Children.Remove(rect);

but this doesn´t delete the rectangles.

And using

canvas.Children.Clear();

delete all childrens inside canvas, and i want to delete only whats inside the big rectangle.

Is there a way to do do it without creating a little canvas inside the big rectangle and doing a .clear to it?

Thank you.

Fernando
  • 23
  • 5
  • Replace the outer rectangle for a `ContentControl` and add the children to that instead of the parent `Canvas`. – Federico Berasategui Aug 13 '18 at 17:06
  • You may want to use an approach like [this](https://stackoverflow.com/a/22325266/1136211) and remove all view model items that are not inside a certain region. – Clemens Aug 13 '18 at 17:25
  • The outer rectangle its a graphical representation, i can´t use a ContentControl for this. Maybe the best solution is to create a canvas inside rectangle. – Fernando Aug 13 '18 at 17:40

0 Answers0