Forcing WPF to create the items in an ItemsControl

前端 未结 6 1299
日久生厌
日久生厌 2021-01-12 18:13

I want to verify that the items in my ListBox are displayed correctly in the UI. I figured one way to do this is to go through all of the children of the

6条回答
  •  隐瞒了意图╮
    2021-01-12 18:15

    For anyone else wondering about this, in Andy's case, perhaps swapping out the VirtualizingStackPanel with a normal StackPanel would be the best solution here.

    The reason calling PrepareItemContainer on the ItemContainerGenerator isn't working is that an item must be in the visual tree for PrepareItemContainer to work. With a VirtualizingStackPanel, the item won't be set as a visual child of the panel until the VirtualizingStackPanel determines that it is/is about to be on screen.

    Another solution (the one I use) is to create your own VirtualizingPanel, so you can control when items are added to the visual tree.

提交回复
热议问题