首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListBox数据虚拟化未生效

ListBox数据虚拟化未生效
EN

Stack Overflow用户
提问于 2011-09-16 15:34:28
回答 2查看 3.5K关注 0票数 4

我从xml中提取了1000个条目,并将它们加载到一个列表对象中。List被数据绑定到水平方向的ListBox,因此用户可以从左到右或从右到左翻阅项目。由于项目数量很大,我的应用程序退出了,可能是因为内存使用过多。如果我将条目减少到50个,它就起作用了。

我找到了这篇文章http://shawnoster.com/blog/post/Improving-ListBox-Performance-in-Silverlight-for-Windows-Phone-7-Data-Virtualization.aspx

然后这篇关于数据虚拟化的文章

http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx

在实现了一个实现了IList的虚拟化类之后,我看不出有什么不同。这个below仍然被调用了1000次,尽管我预计它只会被调用30-40次,因为我知道UI已经在列表框中虚拟化了。为什么虚拟化没有发挥作用?

代码语言:javascript
复制
object IList.this[int index]
{
    get
    {
        if (index >= cachedItems.Count)
        {
            //replenish cache code here
        }

        return cachedItems[index];
    }
    set
    {
        throw new NotImplementedException();
    }
}

以下是与该问题相关的XAML部分。希望这能给出代码的全貌。不确定Width=Auto是否与此有关,但我无法更改它,否则我的滑动停止。

代码语言:javascript
复制
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="0,0,0,0" Width="auto" x:Name="WordsScrollview" Opacity="1"  Grid.Row="1" RenderTransformOrigin="0.5,0.5">

    <ListBox x:Name="horizontalListBox" Width="auto" Height="Auto" >

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal">
                </StackPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Width="430" Text="{Binding Word}"  TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" TextAlignment="Center" />
                    <Image Height="290" HorizontalAlignment="Center" Name="image1" Stretch="Fill"  Width="430" Source="{Binding ImageFile}" Margin="10,50,10,0" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>

        <ListBox.Background>
            <SolidColorBrush />
        </ListBox.Background>

    </ListBox>

</ScrollViewer>
EN

回答 2

Stack Overflow用户

发布于 2011-09-19 02:35:07

这是导致UI虚拟化最终发挥作用的XAML。

代码语言:javascript
复制
        <ListBox x:Name="horizontalListBox"   Height="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" >

                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal">

                        </VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>

                            <StackPanel>
                                <TextBlock Width="430" Text="{Binding Word}"  TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" TextAlignment="Center" />

                                <Image Height="290" HorizontalAlignment="Center" Name="image1" Stretch="Fill"  Width="430" Source="{Binding ImageFile}" Margin="10,50,10,0" />
                               </StackPanel>

                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.Background>
                    <SolidColorBrush />
                </ListBox.Background>
            </ListBox>
票数 3
EN

Stack Overflow用户

发布于 2015-06-25 11:16:58

在接下来的文章中,解释了在ScrollViewer中包装虚拟化UI控件将为其提供无限的空间,从而有效地禁用UI虚拟化

http://blogs.msdn.com/b/mcsuksoldev/archive/2010/04/13/performance-characteristics-of-the-silverlight-datagrid.aspx

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7441510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档