Frederiek
Frederiek

Reputation: 1613

Silverlight: get event when children of panel changes

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.

Upvotes: 1

Views: 1236

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189457

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.

Upvotes: 2

Related Questions