I have a list o开发者_高级运维f 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
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.
Put the Rectangles in an ObservableCollection.
精彩评论