DataBound控制在WP7中加载图像并避免图像缓存

时间:2011-12-21 17:43:22

标签: image windows-phone-7 caching memory

我想将图像加载到Pivot标题中以替换WP7中缺少的Gallery控件。我试图从URL填充它们,并希望确保图像不会保存在缓存中(通过设置UriSource = null)以确保它们不会占用太多资源。

在XAML中没有办法做到这一点,有人可以给我示例代码来处理代码隐藏。我的尝试没有成功。我在这做错了什么?

public class PhotoGalleryVM
{
    public ObservableCollection<BitmapImage> Images
    {
        get
        {
            ObservableCollection<BitmapImage> list = new ObservableCollection<BitmapImage>();
            foreach (RoomImage r in App.appData.currentChoices.roomImages)
            {
                BitmapImage img = new BitmapImage(new Uri(Uri.UnescapeDataString(r.largeUri)));
                img.UriSource = null;
                list.Add(img); 
            }

            return list;
        }

    }
}

1 个答案:

答案 0 :(得分:0)

有一个选项可以忽略图像缓存:

 bitmapImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;

msdn

了解详情