简体   繁体   English

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

[英]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 a

<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 mscorlib.ni.dll中发生了'System.Exception'类型的第一次机会异常

Additional information: The component cannot be found. 附加信息:找不到组件。 (Exception from HRESULT: 0x88982F50) (来自HRESULT的异常:0x88982F50)

at this line 在这条线

 await bitmapImage.SetSourceAsync(stream);

Please, what is the problem? 拜托,这是什么问题?

The program works but the problem was corrupted jpg files. 该程序有效,但问题是jpg文件已损坏。 They had a 0 bytes size so the stream could not be created. 它们的大小为0字节,因此无法创建stream Check if this variable has been created or if it's full of data. 检查此变量是否已创建或是否已满数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Phone 8.1运行时应用程序中显示计划的对话框? - How to show a scheduled dialog in a Windows Phone 8.1 Runtime app? 如何在具有DataBinding的FlipView中显示3张图像 - How to show 3 images in the FlipView with DataBinding Windows Phone 8.1上的flipview错误“名称”在当前上下文中不存在” - flipview on windows phone 8.1 error “The name '' does not exist in the current context” 在Windows Phone 8.1 WinRT中使用FlipView动态分页GridView - Dynamic Paging of GridView with FlipView in Windows Phone 8.1 WinRT 在Windows Phone 8.1上阅读pdf时无法添加翻页图像 - Cannot add flipview image when reading pdf on windows phone 8.1 在Windows Phone 8.1的flipview中对所有照片应用某些功能 - Applying certain functions on all the photos in flipview on windows phone 8.1 如何在Windows App 8.1中的flipview中同时显示图像和媒体元素 - How to display both images and media element inside flipview in windows app 8.1 Windows Phone 8.1运行时在OnNavigatedFrom上显示消息框(后退按钮) - Windows Phone 8.1 runtime show message box on OnNavigatedFrom (back button) Windows Phone 8.1运行时应用 - Windows phone 8.1 runtime apps 在WebView Windows Phone 8.1中显示本地图像 - Show local images inside WebView windows phone 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM