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

0

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?

c#
windows-runtime
windows-phone-8.1
winrt-xaml
flipview
asked on Stack Overflow Sep 27, 2015 by user3290180

1 Answer

0

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.

answered on Stack Overflow Sep 27, 2015 by user3290180

User contributions licensed under CC BY-SA 3.0