我在 XAML 中有一个 longlistselector:
<phone:LongListSelector x:Name="listBox1" ItemsSource="{Binding ListView}" Margin="0,140,0,0">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110" />
<ColumnDefinition Width="210" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<Image Height="110" Width="110" Grid.Column="0" Tap="Image_Tap" Source="{Binding profilePicURL}" Tag="{Binding username}" Margin="0,1"/>
<TextBlock Grid.Column="1" /> // blablabla
<TextBlock Grid.Column="2" /> // blablabla
<Image Grid.Column="3"/> // blablablabla
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
和 ListViewModel.cs
using Newtonsoft.Json;
using System;
using System.ComponentModel;
namespace MyApp
{
public class ListViewModel : INotifyPropertyChanged
{
private string _userid;
[JsonProperty(PropertyName = "userid")]
public string userid
{
get
{
return _userid;
}
set
{
if (value != _userid)
{
_userid = value;
NotifyPropertyChanged("userid");
}
}
}
private string _profilePicURL;
[JsonProperty(PropertyName = "profile_picture")]
public string profilePicURL
{
get
{
return _profilePicURL;
}
set
{
if (value != _profilePicURL)
{
_profilePicURL = value;
NotifyPropertyChanged("profilePicURL");
}
}
}
private string _username;
[JsonProperty(PropertyName = "username")]
public string username
{
get
{
return _username;
}
set
{
if (value != _username)
{
_username = value;
NotifyPropertyChanged("username");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
我用数据库中的 20 条记录填充此列表。一切正常,但我不喜欢应用程序在我刷新列表时再次加载所有图片这一事实。因为当我刷新时,该应用程序再次从互联网加载最近的 20 条记录,并且在这 20 个插槽列表的顶部可能有 1 或 2 个新条目,并且所有其他图片都已加载。那么我怎样才能将旧记录“推”下来,只将新记录加载到顶部。我不想再次下载所有旧图像。我怎样才能缓存它?当然,当较新的条目出现在顶部时,底部的条目将消失。
最佳答案
Save隔离存储文件夹中的图像。从该文件夹中加载 list
中的图像。
现在,当需要添加新图像时,将它们保存到同一文件夹并删除不再需要的图像。
这样,即使用户关闭应用然后重新打开,图像也会被缓存,同时为用户保存数据。
关于c# - Windows Phone 8 Longlistselector 图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376607/