为了让嵌套的列表框正常工作,我已经努力了两天,我在列表框中垂直放置了like类别,然后水平放置了图像。图像的数量可以很容易地达到1000-2000。下面是我的XAML代码:
<ListBox x:Name="CategoryList" VirtualizingStackPanel.VirtualizationMode="Recycling">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid Height="100" Width="480">
<Image HorizontalAlignment="Left" Width="80" Height="80" Margin="0,20,0,0" Source="/Images/listicons14.png"/>
<Rectangle HorizontalAlignment="Right" Width="390" Height="80" VerticalAlignment="Bottom" Fill="#FF7BB800"/>
<TextBlock Text="{Binding Category}" Margin="121,45,0,25" HorizontalAlignment="Left" Width="100"/>
</Grid>
<ListBox VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding Advertisements}" x:Name="Advertisement" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="220" Width="300">
<Border BorderBrush="#FF7BB800" BorderThickness="3" HorizontalAlignment="Center" Width="275" Height="190" VerticalAlignment="Center">
<Image Source="{Binding AdvertisementImage}" Width="275" Height="190"/>
</Border>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>这就是我现在如何填充它(这是作为调试目的,只使用三个不同的图片来填充它。图片的大小约为70kb,但我也测试了非常小的jpeg (每个10kb),没有任何影响。
for (int i = 0; i < 20; i++)
{
ProductCategory productcategory = new ProductCategory { Category = "Book" + i.ToString() };
productcategory.Advertisements = new List<Advertisement>();
for (int j = 0; j < 10; j++)
{
productcategory.Advertisements.Add(new Advertisement { AdvertisementImage = new Uri("/Images/advGalaxyS2reduced.jpg", UriKind.Relative) });
productcategory.Advertisements.Add(new Advertisement { AdvertisementImage = new Uri("/Images/adviphone4sreduced.jpg", UriKind.Relative) });
productcategory.Advertisements.Add(new Advertisement { AdvertisementImage = new Uri("/Images/advLumia800reduced.jpg", UriKind.Relative) });
}
productcategories.Add(productcategory);
}
this.CategoryList.ItemsSource = productcategories;我也已经用Telerik的Listbox测试过了,它肯定更好,但不是“可卖”的,所以我仍然想知道我在这里错过了更多。在我看来,数据虚拟化是开启的,如果我查看它消耗的RAM的数量。请帮我解决这个问题:)
发布于 2012-02-03 18:31:58
我怀疑是嵌套的列表框导致了问题,因为布局引擎需要在滚动时不断地重新测量所有内容。我希望将布局更改为具有固定项目大小的布局,然后看看是否仍然存在相同的问题。
以下是其他一些更通用的指针:
同时显示
发布于 2012-02-06 17:30:58
1000张图片也是别人说的lot..as。尝试使用lowProfileImage加载器
http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx
这不是您的问题的确切解决方案,但它可能会给您提供关于性能改进的想法
https://stackoverflow.com/questions/9126692
复制相似问题