簡體   English   中英

將大量項目加載到列表框時,應用程序崩潰

[英]app crash while loading large amount of items to listbox

我正在開發Windows Phone8應用程序,我有一個顯示大量項目的ListBox,在ListBox的數據模板中也有一個圖像控件。

當我加載前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。 我看到了Silverlight for Windows Phone 7:數據虛擬化中的Listbox性能提高,以及更多類似的示例,但是我不知道要解決此問題。

請給我一些想法。 謝謝。

兩個建議。 首先,如果您必須使用ListBox,則可以通過閱讀ListBox為什么會消隱來獲得更好的性能和圖像虛擬化。 在Windows Phone開發團隊的這篇文章中,他們提到了設置圖像的另一種方法。

<Image> 
    <Image.Source> 
        <BitmapImage UriSource="{Binding ImgUrl}" CreateOptions="BackgroundCreation"/> 
    </Image.Source> 
</Image>

第二個建議(可能更好)是不使用LstBox,而是使用LongListSelector 使此控件性能更好,並使用了更少的內存。 只需在xaml中執行從ListBox到LongListSelector的查找/替換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM