Getting UI virtualization working with ItemsControl in Silverlight

一世执手 提交于 2019-12-01 17:21:22

There are a few things you need to do to make this work.

  1. Set the ItemsPanelTemplate for your ItemsControl to a VirtualizingStackPanel.
  2. Incorporate the ScrollViewer inside a ControlTemplate for your ItemsControl instead of just wrapping it around the outside.
  3. Make sure the ItemsControl has a fixed height so the layout system can work out how many items it needs to fill the viewport. (It looks like you are already doing this by putting the ItemsControl in a Grid - that will allow the layout system to determine the alloted height for the control)

Here's the simplest example I could come up with of this working:

    <ItemsControl ItemsSource="{Binding TextItems}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.Template>
            <ControlTemplate TargetType="ItemsControl">
                <Border>
                    <ScrollViewer>
                        <ItemsPresenter/>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!