Silverlight:当面板的子级发生变化时获取事件
添加或删除子项时,有没有办法从 Panel
获取事件? 我从 WrapPanel
atm 获取。
Is there a way to get a event from a Panel
when a child is added or removed?
I'm deriving from a WrapPanel
atm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有公共事件或受保护的覆盖来跟踪
Children
成员资格的更改。但是,Children
属性的成员资格更改最终将导致LayoutUpdated
事件。如果您只需要知道成员是否已更改,那么最后一个子项计数的简单副本就足够了。但是,如果您需要跟踪已添加或删除的成员,那么您将需要完成工作,维护影子集合,比较集合并确保您不会保留应从影子中删除的条目收藏。
请记住,由于各种其他原因,
LayoutUpdated
可能会相当频繁地发生,因此您附加到它的任何代码都需要尽快完成。由于您对可视化树所做的任何更改也可能会触发另一个LayoutUpdated
,因此需要小心以避免创建无限循环。There is no public event or protected override that tracks changes
Children
membership. However a change in the membership of theChildren
property will ultimately result in aLayoutUpdated
event.If you just need to know if the members have been changed then a simple copy of the last count of children would suffice. However if you need to keep track of which members have been added or removed then you will have your work cut out for you, maintaining shadow collection, comparing the collections and ensure you don't hold on to entries that should be removed from your shadow collection.
Bear in mind that
LayoutUpdated
can happen fairly frequently for all sorts of other reasons so any code you attach to it needs be done as quick as possible. Since any changes you might make to the visual tree might also trigger anotherLayoutUpdated
care is needed to avoid creating an infinite loop.