Silverlight: get event when children of panel changes

自古美人都是妖i 提交于 2019-12-24 11:00:25

问题


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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/5855094/silverlight-get-event-when-children-of-panel-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!