WPF 绑定网格子 UIElementCollection
我有一个保留在内存中的矩形形状列表,
我想将此矩形列表绑定到网格,以便网格将矩形显示为其子项。
因此,当我更新此矩形列表(添加、删除)时,它将在显示中更新。 我知道我可以通过访问网格的孩子属性并添加和删除矩形来以编程方式完成此操作,但由于难以解释的原因,我想使用绑定功能......
这可能吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,您应该使用 itemscontrol,因为无法直接绑定到面板的 Children 属性。请参阅此示例了解相同的情况,只不过它使用的是画布。
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.
将矩形放入 ObservableCollection 中。
Put the Rectangles in an ObservableCollection.