是否可以绑定到Canvas.Children?
我不知道这是否是最好的方法,但我想做的是创建 Shape
对象的集合,然后将其绑定到 Canvas
,然后每当我更新这些 Shapes
或添加新的 Shapes
(罕见)时,Canvas
上的 Shape
对象都会更新以及。
顺便说一句,Shape
对象并不完全相同,有一些 Lines
、Rectangles
等。不确定这是否重要。
最好的方法是什么?
I don't know if this is the best way, but what I am trying to do is to create a collection of Shape
objects and then bind it to a Canvas
, then whenever I update these Shapes
, or add new Shapes
(rare), the Shape
objects on the Canvas
will update as well.
Btw the Shape
objects are not all the same, some Lines
, Rectangles
, etc. Not sure if that matters.
What's the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看问题是吗可以在 XAML 中绑定 Canvas 的 Children 属性吗? 进一步,Ivan 提供了一个答案,它使用您可以绑定的附加属性,并且它会自动更新画布子级。我还没有尝试过,但看起来应该有效。对我来说似乎是最好的解决方案。另一种选择是将
ItemsControl
与DataTemplate
一起用于您想要显示的每种类型 - 但这似乎有点繁琐。If you look at the question Is it possible to bind a Canvas's Children property in XAML? and further down there is an answer from Ivan which uses an attached property you can bind to and it automatically updates the canvas children. I haven't tried it but looks like it should work. Seems the best solution to me. The other option is to use the
ItemsControl
with aDataTemplate
for each type you want to show - however that seems a bit fiddly.