如何加速Silverlight滚动查看器?

时间:2013-01-02 22:02:32

标签: silverlight scrollviewer

我的Silverlight客户端中有ScrollViewer,显示所选类别中的项目列表。选中时,项目会更改大小。在正常情况下,ScrollViewer工作正常,但一个类别有近300个项目。选择此类别后,ScrollViewer几乎无法使用。它是否呈现列表中的所有内容?有没有办法可以加快速度?

1 个答案:

答案 0 :(得分:0)

我找到了一个可能有用的解决方案:

<!-- This needs to be contained in a parent panel like a grid -->
<ListBox x:Name="Items" >
    <ListBox.Template>
        <ControlTemplate> <!-- Broke it out to allow resizing -->
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <ItemsPresenter/> <!-- This little fella does magical things -->            
            </ScrollViewer>         
        </ControlTemplate>      
    </ListBox.Template>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel VirtualizingStackPanel.VirtualizationMode="Recycling"/>  <!-- Recycle was a must -->        
        </ItemsPanelTemplate>       
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <HyperlinkButton  VerticalAlignment="Top" Margin="5" />
                <!-- This guy I did need to set a minwidth on to retain nice and predictable scrolling  when datacontext was potentially changing -->
                <ContentControl cal:View.Model="{Binding}" MinWidth="1160" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" />
            </StackPanel>
        </DataTemplate>         
    </ListBox.ItemTemplate>           
</ListBox>