My controls .ItemContainerGenerator.Status is NotStarted. How do I tell it to start now and wait until it is completed?
Asked
Active
Viewed 4,556 times
4
-
See my updated answer to your other question. http://stackoverflow.com/questions/2480850/wpf-how-do-i-set-the-focus-on-a-datagrid/2480901#2480901 – Taylor Leese Mar 19 '10 at 23:03
3 Answers
9
You may want to start the generator manually if you doing some syncronous operation - I had to generate the result view to meassure it before chunking it up on pages.
IItemContainerGenerator generator = (child as ListContent).ItemContainerGenerator;
GeneratorPosition position = generator.GeneratorPositionFromIndex(0);
using (generator.StartAt(position, GeneratorDirection.Forward,true))
{
foreach (object o in (child as ListContent).Items)
{
DependencyObject dp = generator.GenerateNext();
generator.PrepareItemContainer(dp);
}
}

Hans Karlsen
- 91
- 1
- 2
1
Bind and show the ItemsControl. The ItemContainerGenerator will start and generate items as part of the data binding cycle.
If you really need to manually start the generator, you may be able to do so by calling IItemContainerGenerator.StartAt. This is an explicit interface implementation so you will need to cast the ItemsControl.ItemContainerGenerator property, e.g. ((IItemContainerGenerator)(listBox.ItemContainerGenerator)).StartAt(...);
. But manually starting the generator is very rarely necessary in application code.

itowlson
- 73,686
- 17
- 161
- 157
-
Alas this doesn't do what I want. While it does indeed start the item generation, it doesn't wait until they are complete. – Jonathan Allen Mar 20 '10 at 05:34
-
I guess you could poll for GeneratorStatus.ContainersGenerated, but it depends on what you're trying to do. – itowlson Mar 20 '10 at 08:24
0
You can use
ItemContainerGenerator.StatusChanged
event to handle when status are changed

Dmitriy Kudinov
- 1,051
- 5
- 23
- 31