Hey guys, I'm having problems with the ItemContainerGenerator in Silverlight 3.
In my derived Custom ListBox I'm adding this handler:
ItemContainerGenerator.ItemsChanged += new ItemsChangedEventHandler(ItemContainerGenerator_ItemsChanged);
Every time the Items change I'm getting a call back. Fine so far.
Now in the ItemContainerGenerator_ItemsChanged I want to do different things depending on the action like this:
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
Debug.WriteLine("items added");
break;
case NotifyCollectionChangedAction.Remove:
Debug.WriteLine("items removed");
break;
case NotifyCollectionChangedAction.Replace:
Debug.WriteLine("items removed");
break;
case NotifyCollectionChangedAction.Reset:
Debug.WriteLine("items reset, itemscount:" + this.Items.Count);
CalcMaxColumnWidths();
break;
default:
break;
}
Everything works fine until now. In the CalcMaxColumnWidths() i call when the action is reset I do this:
foreach (ListBoxItem item in ItemsControlExtensions.GetContainers(this))
{ //some code here }
Here's the problem:
The Containers I'm trying to get with the GetContainers() method returns null, even though the Items.Count is the correct value (60).
In WPF there was a ItemContainerGenerator.Status, so we could wait until that was set to Done and then iterate over the containers.
How can i solve this in Silverlight? (without any Timers!)
Thanks for your help!