【发布时间】:2013-07-25 09:44:33
【问题描述】:
我正在开发一个 windows phone8 应用程序 我有一个显示大量项目的列表框,我在列表框的数据模板中也有一个图像控件。
当我加载前 100 个项目时,它运行良好,当我加载接下来的 100 个项目(总共 200 个)时,会发生应用崩溃。
谁能帮我解决这个问题。
这是我的列表框代码
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" Visibility="Visible" x:Name="commentsListBox" VerticalAlignment="Top" >
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#FFB9B9B9" BorderThickness="0,0,0,2" Width="462" Margin="14,0,0,0">
<Grid VerticalAlignment="Top" Width="470" >
<Image HorizontalAlignment="Left" Height="100" Width="100" VerticalAlignment="Top" Margin="10,20,0,0" Stretch="Fill" Source="{Binding profileImage}"></Image>
<TextBlock Name="userNameTextBlock" VerticalAlignment="Top" FontWeight="Bold" HorizontalAlignment="Left" Text="{Binding userName}" Foreground="Black" Height="36" Width="238" Margin="136,18,0,0" TextTrimming="WordEllipsis" FontFamily="Tahoma" />
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" Margin="146,68,0,0" Width="314">
<TextBlock Name="commentTextBlock" VerticalAlignment="Top" TextAlignment="Left" HorizontalAlignment="Left" Foreground="Black" Text="{Binding comment}" Width="313" TextWrapping="Wrap" FontFamily="Tahoma" Margin="0,0,-17,0" ></TextBlock>
<TextBlock Text="{Binding date}" Height="36" Foreground="Red" Width="264" Name="commentDate" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,10,0" TextTrimming="WordEllipsis" FontFamily="Tahoma"></TextBlock>
<Button HorizontalAlignment="Right" Width="100" Content="View" Height="70" FontSize="18" x:Name="viewBtn" Background="#FFD71D26" VerticalAlignment="Bottom" Margin="0,0,-10,-10"></Button>
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<!--<ListBoxItem>
</ListBoxItem>-->
</ListBox>
有数据的类是
public class WishListCommentCommonFormate
{
public string comment { get; set; }
public string userName { get; set; }
public DateTime date { get; set; }
public string profileImage { get; set; }
}
这里的图片是来自网站的 URL。 我看到了Improving ListBox Performance in Silverlight for Windows Phone 7: Data Virtualization 和其他几个类似的例子,但我没有解决这个问题的想法。
请给我一些想法。 谢谢。
【问题讨论】:
-
您的内存不足。您需要使用更少的 RAM。
标签: c# image xaml windows-phone-8 windows-phone