Windows手机应用程序内存不足

时间:2013-08-20 09:03:20

标签: c# xaml memory binding windows-phone-8

目前我的视图绑定到后面代码中的数据,以便在列表框中显示带有2个子标题的图片。但是当我加载到很多记录时,Windows Phone会耗尽内存。我已经让应用程序一次只加载10条记录,所以当用户向下滚动时,还有10条记录加载等等。但问题是当用户加载200条或更多记录时手机仍然耗尽内存约有2600条记录。

  <ListBox x:Name="geklassifisseerd_list" 
                         VerticalAlignment="Top"
                         ItemsSource="{Binding ClassifiedAds}"
                         SelectionChanged="geklassifisseerd_list_SelectionChanged_1"
                         Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="5">
                                <Image Source="{Binding ImageUrl}" 
                                   Height="140"
                                   Width="160"/>

                                <TextBlock Text="{Binding Title}" 
                                       TextWrapping="Wrap" 
                                       Margin="2" 
                                       Width="160"
                                       Foreground="Black"
                                       FontWeight="Bold"
                                       FontSize="15"/>

                                <TextBlock Text="{Binding CreationDate}" 
                                       TextWrapping="Wrap" 
                                       Foreground="Black"
                                       Margin="2,0,0,5" 
                                       FontSize="13"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Controls:WrapPanel Orientation="Horizontal"  />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

模特:

 public class ClassifiedAds : INotifyPropertyChanged
{
    public int ID { get; set; }
    public string Title { get; set; }

    private string _body;
    public string Body
    {
        get { return _body; }
        set { _body = HTMLHelper.ConvertHtmlToText(value); }
    }

    public string CategoryName { get; set; }
    public string ContactEmail { get; set; }
    public string ContactTel { get; set; }
    public DateTime CreationDate { get; set; }
    public DateTime DisplayUntilDate { get; set; }
    public Gal Gallery { get; set; }
    public string ImageUrl { get; set; }
    public bool IsActive { get; set; }
    public bool IsDeleted { get; set; }
    public DateTime LastUpdateDate { get; set; }
    public string PhysicalAddress { get; set; }
    public string Price { get; set; }
    public string ProvinceName { get; set; }
    public int TotalViews { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

我不知道如何加载数据,因为需要显示所有记录,是否可以在用户向下滚动时卸载以前的记录?或者我可以尝试别的什么?

0 个答案:

没有答案
相关问题