![](/img/trans.png)
[英]How to bind to a specified element of an array to image source in LongListSelector in windows phone 8
[英]Windows Phone 8 Longlistselector Image Cache
我在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個新條目,並且所有其他圖片已經加載。 那么我怎樣才能“推”舊的那些並且只在頂部加載新記錄。 我不想再次下載所有舊圖像。 我該如何緩存它? 當然,當較新的條目出現在頂部時,底部的條目將消失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.