开发者

WPF Binding Grid Children UIElementCollection

开发者 https://www.devze.com 2023-02-19 07:15 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消