问题描述
大家好
我正在使用LongListSelector向用户显示歌曲(它们位于服务器上)。
下面是用于LongListSelector的 ItemTemplate
< DataTemplate x:Key =" AppTopItemsTemplate">
< Grid Margin =" 10">
< Grid.RowDefinitions>
< RowDefinition Height =" *" />
< RowDefinition Height =" 50" />
< /Grid.RowDefinitions>
< Grid.ColumnDefinitions>
< ColumnDefinition Width =" *">< / ColumnDefinition>
< /Grid.ColumnDefinitions>
< Image Name =" itemImage" Grid.Row = QUOT; 0" Grid.Column = QUOT; 0" Grid.RowSpan = QUOT; 2英寸伸展= QUOT; UniformToFill"
>
< Image.Source>
< BitmapImage UriSource =" {Binding ImageUrl}"
CreateOptions =" BackgroundCreation" />
< /Image.Source>
< / Image>
< StackPanel Grid.Row =" 1" Grid.Column = QUOT; 0"取向= QUOT;垂直"背景= QUOT;#99000000" >
< TextBlock Name =" itemTitle" Style =" {StaticResource AppItemTitleSubtitle}"
Text =" {Binding Title}"
>< / TextBlock>
< TextBlock Name =" itemSubTitle" Style =" {StaticResource AppItemTitleSubtitle}"
Text =" {Binding SubTitle}"填充= QUOT; 0,0,0,5" >< / TextBlock的>
< / StackPanel>
< / Grid>
< / DataTemplate>
ImageUrl 是图像控制的远程图像网址。
我实现了LongListSelector,下面是无限滚动代码。
private void List_ItemRealized_1(object sender,ItemRealizationEventArgs e)
{
if(songList.ItemsSource as ObservableCollection< SongTable> == null)
{
return;
}
int indexofRealizeditem = songsDataSource.Items.IndexOf(sngItem);
if(!songsDataSource.IsLoading&&(e.Container.Content as SongTable)!= null&& e.ItemKind == LongListSelectorItemKind.Item&&(indexofRealizeditem == currentCount - 1) )
{
//一旦实现最后一项我将从server.loadmore加载更多项目是异步调用它不会阻止ui线程。
songsDataSource.loadMore();
}
}
一切正常,但是当LongListSelector中加载超过 1000个项目时,它会抛出Out of Memory Exception。
由于我正在从服务器加载图片,这可能是原因但我如何为项目发布
内存这是由LongListSelector未实现的。
当项目未实现时,我将图像控制的源设置为null但它没有帮助。
任何人都可以建议我如何 我可以解决这个问题。
为了您在我的服务器上的信息,我有大约10000项。
Hi All
I am using LongListSelector to show songs(they are located on server) to the user.
Below is the ItemTemplate used for LongListSelector
<DataTemplate x:Key="AppTopItemsTemplate"> <Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="50"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions > <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <Image Name="itemImage" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Stretch="UniformToFill" > <Image.Source> <BitmapImage UriSource="{Binding ImageUrl}" CreateOptions="BackgroundCreation"/> </Image.Source> </Image> <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Vertical" Background="#99000000" > <TextBlock Name="itemTitle" Style="{StaticResource AppItemTitleSubtitle}" Text="{Binding Title}" ></TextBlock> <TextBlock Name="itemSubTitle" Style="{StaticResource AppItemTitleSubtitle}" Text="{Binding SubTitle}" Padding="0,0,0,5" ></TextBlock> </StackPanel> </Grid> </DataTemplate>
ImageUrl is the Remote Image Url for the Image Control.
I had implemented LongListSelector with infinite scrolling below is the code.
private void List_ItemRealized_1(object sender, ItemRealizationEventArgs e) { if (songList.ItemsSource as ObservableCollection<SongTable> == null) { return; } int indexofRealizeditem = songsDataSource.Items.IndexOf(sngItem); if (!songsDataSource.IsLoading && (e.Container.Content as SongTable) != null && e.ItemKind == LongListSelectorItemKind.Item && (indexofRealizeditem == currentCount - 1)) { // as soon as last item is realized I am loading more items from server.loadmore is async call it is not blocking ui thread. songsDataSource.loadMore(); } }
Everything works fine for me But when more than 1000 items are loaded in LongListSelector It throws Out of Memory Exception.
Since I am Loading images from server this might be the cause but How will I release theMemory for items which are unrealized by LongListSelector.
When Items are unrealized I am setting source of Image Control to null but its not helping.
Can any one suggest me How I can resolve this issue.
For you information on my server I am having around 10000 items.
这篇关于内存不足异常在Windows Phone 8上使用LongListSelector时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!