windows-phone-7 – ListBox数据虚拟化没有生效
发布时间:2020-12-14 05:26:50 所属栏目:Windows 来源:网络整理
导读:我从xml获得了1000个项目并将它们加载到List对象中. List是数据绑定到ListBox,它是水平方向的,因此用户可以从左到右或从右到左翻阅项目.由于项目数量巨大,我的应用程序可能因内存使用过多而退出.如果我将项目减少到50就可以了. 我找到了这篇文章 http://shaw
我从xml获得了1000个项目并将它们加载到List对象中. List是数据绑定到ListBox,它是水平方向的,因此用户可以从左到右或从右到左翻阅项目.由于项目数量巨大,我的应用程序可能因内存使用过多而退出.如果我将项目减少到50就可以了.
我找到了这篇文章 然后这篇关于数据虚拟化的文章 http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx 在实现实现IList的虚拟化类之后,我发现没有区别.这个[](下面)被称为1000次,虽然我预计它只会被调用30-40次,因为我知道UI已经在Listbox中虚拟化了.为什么虚拟化没有开始? object IList.this[int index] { get { if (index >= cachedItems.Count) { //replenish cache code here } return cachedItems[index]; } set { throw new NotImplementedException(); } } 这是与问题相关的XAML部分.希望这能够全面了解代码.不确定Width = Auto是否与它有关但我无法更改它,否则我的刷卡停止. <ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="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> 解决方法
以下是导致UI虚拟化最终启动的XAML.
<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,0" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> <ListBox.Background> <SolidColorBrush /> </ListBox.Background> </ListBox> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- windows-7 – “Windows Virtual PC”和“Micros
- Windows Phone 8仿真器 – 部署通用应用程序导致
- windows-server-2003 – 用户无法访问Windows Se
- Windows – 在批处理文件中删除目录树的最快方式
- Microsoft符号服务器/本地缓存哈希算法
- windows-server-2008-r2 – 在Windows Server 20
- .net – 十进制为主键在Dev(Win7 / 64bit)中工作
- windows – msi for Web Deploy 3.6 for Hosting
- 有没有一个很好的Fogbugz客户端Windows
- windows – 为什么我的Ruby线程演示不使用两个内
热点阅读