Why does ItemContainerGenerator return null?

前端 未结 5 2004
闹比i
闹比i 2020-12-21 23:53

I have a ListBox, and I need to set its ControlTemplate to a Virtualizing WrapPanel which is a class that extends VirtualizingPanel, using a style that looks like this:

5条回答
  •  滥情空心
    2020-12-22 00:49

    I think I had a similar problem and this helped:

    var necessaryChidrenTouch = this.Children;
    IItemContainerGenerator generator = this.ItemContainerGenerator;
    

    ... for some reason you have to "touch" the children collection in order for the ItemContainerGenerator to initialize properly.

提交回复
热议问题