Windows Phone 8.1(运行时):如何在FlipView中显示图片列表?

Windows Phone 8.1 (Runtime): How to show a list of images in a FlipView?

我是这样做的:

    using Windows.Storage;
    using Windows.UI.Xaml.Media.Imaging;

    ...

    private async void LoadFiles()
    {
        StorageFolder folder = KnownFolders.SavedPictures;
        IReadOnlyList<StorageFile> list = await folder.GetFilesAsync();
        var images = new List<BitmapImage>();
        if (list != null)
        {
            foreach (StorageFile file in list)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                BitmapImage bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(stream);
                images.Add(bitmapImage);

            }
        }
        flipView.ItemsSource = images;
    }

xaml

<FlipView x:Name="flipView"
              SelectionChanged="flipView_SelectionChanged">
        <FlipView.ItemTemplate>
            <DataTemplate>
                <Image Stretch="UniformToFill" Source="{Binding}" />
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>

我得到这个异常

A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll

Additional information: The component cannot be found. (Exception from HRESULT: 0x88982F50)

在这一行

 await bitmapImage.SetSourceAsync(stream);

请问是什么问题?

该程序可以运行,但问题是 jpg 文件已损坏。 它们的大小为 0 字节,因此无法创建 stream。 检查此变量是否已创建或是否已充满数据。