WPF: control.ItemContainerGenerator.Status is NotStarted. How do I tell it to start now?

前端 未结 3 803
梦如初夏
梦如初夏 2021-01-19 08:01

My controls .ItemContainerGenerator.Status is NotStarted. How do I tell it to start now and wait until it is completed?

相关标签:
3条回答
  • 2021-01-19 08:45

    You can use

    ItemContainerGenerator.StatusChanged
    

    event to handle when status are changed

    0 讨论(0)
  • 2021-01-19 08:51

    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.

    0 讨论(0)
  • 2021-01-19 09:04

    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);
                            }
       }
    
    0 讨论(0)
提交回复
热议问题