-1

My ItemControl is binded via ItemsSource to an ObservableCollection<...>. When I fill the collection, the program needs some (a little, but still some) time to create right ItemTemplate objects and render them in my ItemsControl. Is there any way to get known, if my ItemsControl has ended creating (rendering, displaying) the collection binded through the ItemsSource? Please, help. I really need this answer. Just after filling the ObservableCollection I want to work on the objects of this collection. Unfortunatly, some of the informations is being lost, cuz ItemsControl is still creating it's items (ItemTemplates).

*EDIT To be better understood: ObservableCollection<...> MyCollection is binded to ItemsSource of MyItemsControl.

I run the code:

for(int i = 0; i < ...; i++)
{
    MyCollection.Add(MyItem);
}

// await Task.Delay(100) // If this line is not commented, everything works fine...
// ..but I don't think it's a good idea to solve that problem in this way.

foreach(Object o in MyCollection)
{
    // The line under, is faster that the ItemsControl rendering...
    // ...so the Work is not displayed.
    o.DoSomeWorkThatShouldBeDisplayedInItemTemplateOfMyItemsControl
}

*EDIT 2 Solved: LayoutUpdated event

2 Answers2

0

I got it. LayoutUpdated event is what I need. Found on another forum, but hope to help sb in the future.

  • maybe it's just me, but a little more detail on how that helped you would probably be needed to help others. – kenny Nov 19 '12 at 13:13
  • So, I needed to know when the ItemsControl ends rendering its items. And LayoutUpdated is the event raised when it does it's work. It's raised, when the change in ItemsControl is 'applied (item is changed/added/removed, and rendered'. So I do my o.DoSomeWorkThat... in that event. Unfortunatly, it's not perfect, cuz it's raised every time the change is made. I wish to have an event, which is raised when specified elements are created. But it a good starting point for me. – jozefkarton Nov 19 '12 at 19:21
-1

Try System.Windows.Forms.Application.DoEvents();

Manolo
  • 164
  • 1
  • 5