开发者

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

开发者 https://www.devze.com 2022-12-23 18:52 出处:网络
My controls .ItemContainerGenerator.Status is NotStarted. How do I tell it to start now and wait until it is com开发者_StackOverflow社区pleted?You may want to start the generator manually if you doing

My controls .ItemContainerGenerator.Status is NotStarted. How do I tell it to start now and wait until it is com开发者_StackOverflow社区pleted?


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);
                        }
   }


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.


You can use

ItemContainerGenerator.StatusChanged

event to handle when status are changed

0

精彩评论

暂无评论...
验证码 换一张
取 消