Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将大量项目加载到listbox时应用程序崩溃_C#_Image_Xaml_Windows Phone 8_Windows Phone - Fatal编程技术网

C# 将大量项目加载到listbox时应用程序崩溃

C# 将大量项目加载到listbox时应用程序崩溃,c#,image,xaml,windows-phone-8,windows-phone,C#,Image,Xaml,Windows Phone 8,Windows Phone,我正在开发一个windows phone8应用程序 我有一个显示大量项目的列表框,在列表框的数据模板中也有一个图像控件 当我加载前100项时,它工作正常,当我加载下100项(总共200项)时,应用程序崩溃发生 谁能帮我解决这个问题 这里是列表框的代码 <ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" Visibility="Visible" x:Name="commentsListBox" VerticalAlignm

我正在开发一个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>
在这里,图像是作为一个网站的URL提供的。 我看到了很多这样的例子,但是我没有办法解决这个问题

请告诉我一些想法。
谢谢。两条建议。首先,如果您必须使用列表框,那么通过阅读,您的图像将具有更好的性能和虚拟化。在这篇来自Windows Phone开发团队的文章中,他们提到了一种不同的设置图像的方法

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


第二个建议(可能更好)是不要使用LstBox,而是使用。此控件的目的是提高性能,并减少内存使用。只需在xaml中执行从ListBox到LongListSelector的查找/替换操作。

两条建议。首先,如果您必须使用列表框,那么通过阅读,您的图像将具有更好的性能和虚拟化。在这篇来自Windows Phone开发团队的文章中,他们提到了一种不同的设置图像的方法

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


第二个建议(可能更好)是不要使用LstBox,而是使用。此控件的目的是提高性能,并减少内存使用。只需在xaml中执行从ListBox到LongListSelector的查找/替换。

内存不足。您需要使用更少的RAM。内存不足。您需要使用更少的RAM。您好,谢谢您的回复,我将尝试LongListSelector并更新响应。您好,谢谢您的回复,我将尝试LongListSelector并更新响应。