1

I have a list of Rectangle shapes which I keep in memory,

I want to bind this list of rectangles to a Grid so that the Grid will display the rectangles as its children.

So when I update this list of rectangles (adding, removing) it would be updated in the display. I know I can do this programatically by accessing the children property of the Grid and adding and removing the rectangles but for difficult reasons to explain I want to use the Binding feature....

Is this possible?

Thanks

TheWommies
  • 4,922
  • 11
  • 61
  • 79

2 Answers2

4

You should use an itemscontrol in this case, since binding directly to the Children property of a panel is not possible. See this example for the same situation, except that it's using a canvas.

Community
  • 1
  • 1
Bas
  • 26,772
  • 8
  • 53
  • 86
  • 1
    [A more detailed answer](http://stackoverflow.com/questions/1395701/how-do-you-bind-a-grids-children-to-a-list) explaining how one might use the `ItemsControl` to do this. – Roman Starkov Aug 25 '12 at 11:09
0

Put the Rectangles in an ObservableCollection.

Kai G
  • 3,371
  • 3
  • 26
  • 30