Silverlight:当面板的子项发生更改时获取事件 [英] Silverlight: get event when children of panel changes
问题描述
是否有一种方法可以在添加或删除孩子时从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.
推荐答案
没有可跟踪更改Children
成员资格的公共事件或受保护的替代.但是,Children
属性的成员身份更改最终将导致LayoutUpdated
事件.
There is no public event or protected override that tracks changes Children
membership. However a change in the membership of the Children
property will ultimately result in a LayoutUpdated
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.
请记住,由于各种其他原因,LayoutUpdated
可能会相当频繁地发生,因此,您附加到它的任何代码都需要尽快完成.由于您可能会对可视化树进行的任何更改也可能触发另一个LayoutUpdated
注意,因此需要避免创建无限循环.
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 another LayoutUpdated
care is needed to avoid creating an infinite loop.
这篇关于Silverlight:当面板的子项发生更改时获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!