我正在开发一个使用列表框的 Windows 手机应用程序。我正在绑定媒体库中的一些图像。但是加载需要很长时间。因此,如果媒体库中有很多图像,则需要很长时间。
private List<img> _galleryImages = new List<img>();
public void getImages()
{
try
{
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
foreach (var picture in pictures)
{
BitmapImage image = new BitmapImage();
image.SetSource(picture.GetImage());
img mediaImage = new img();
mediaImage.Imgs = image;
_galleryImages.Add(mediaImage);
}
}
catch (Exception ex)
{
}
}
public class img
{
public BitmapImage Imgs { get; set; }
}
在xml中......
<toolkit:LongListSelector x:Name="imageList" IsFlatList="True" >
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate >
<Image Name="im" Source="{Binding img}" Width="100" Height="100"/>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
private void imageList_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
MediaLibrary mediaLibrary = new MediaLibrary();
BitmapImage image = new BitmapImage();
image.SetSource(mediaLibrary.Pictures[imageList.SelectedIndex].GetImage());
image1.Source = image;
}
所以请给我一些提示,让我能够如此快速地将图像从媒体库加载到列表框......