简体   繁体   中英

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

I'm doing this way:

    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>

I get this exception

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

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

at this line

 await bitmapImage.SetSourceAsync(stream);

Please, what is the problem?

The program works but the problem was corrupted jpg files. They had a 0 bytes size so the stream could not be created. Check if this variable has been created or if it's full of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM