Silverlight Canvas 儿童集合已更改
如果 Silverlight 中画布的 childcollection 发生变化,有没有办法捕获? (当添加或删除一个孩子时)
我知道 ObservableCollection 有这样一个事件,我如何为我的 Canvas 引发一个事件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIElementCollection 或 Canvas 对象不会引发此类事件,但是,从 Canvas.Children 集合中添加或删除元素将触发测量传递,然后触发布局更新传递,这意味着 LayoutUpdated 事件将被引发,但是在许多情况下也会引发该事件(如调整大小)。这是您可以了解画布的子集合可能已被修改的结束,除非您自己完成所有添加和删除操作。
No such event is raised by UIElementCollection or the Canvas object, however, adding or removing an element from Canvas.Children collection will trigger measure pass followed by an layout update pass, meaning the LayoutUpdated event will be raised, however the event is also raised in many cases (like resizing). This is the closes you can get to knowing a canvas's child collection could have been modified, unless you do all the adding and removing yourself.
面板的唯一职责是设置其子级的位置和大小。这是在 MeasureOverride 和 ArrangeOverride 这两个有点“纯粹”的过程中完成的。继承自 ItemsControl 以获得更多控制。
The only responsibility of a Panel is setting the position and size of its children. This is done in MeasureOverride and ArrangeOverride, two somewhat 'pure' procedures. Inherit from ItemsControl to get more control.