views:

373

answers:

2

I have an ItemsControl bound to an ObservableCollection. When the observable collection changes, I have an event handler that looks at the children of the ItemsControl. Unfortunately, the ItemsControl hasn't yet added a new item at that time (which is understandable). How can I know when an ItemsControl has finished adding new child controls?

In other words, if I use an ItemsControl to display a list of textboxes, how can I be notified when a new TextBox control has been added to the display?

A: 

Well, I ended up digging into the control to find the ContentPresenter. I then attached to the LayoutUpdated event, which counted the children to see if it changed.

It's kind of a bizarre solution, but it works.

Jason Young
A: 

If you bind an ObservableCollection to the ItemsControl, which happens to be the type of collection that silverlight WCF clients generate, then you can listen to the events raised by the ObservableCollection.

This is actually how Silverlight knows whether to re-renderer or not. You can operate on the collection independent of the UI and the UI behaves normally.

BC