为什么我的翻页视图没有显示任何图片? [英] Why is my flipview not showing any pictures?

查看:41
本文介绍了为什么我的翻页视图没有显示任何图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我可以选择多个文件,但是当我点击打开时,没有显示选定的图像.相反,Windows.UI.XAML.Media.Imaging.BitmapImage"显示为文本.FlipView 功能仍然存在.我做错了什么?

Currently I am able to select multiple files but when I click open, the selected images are not being shown. Instead, "Windows.UI.XAML.Media.Imaging.BitmapImage" appears as a text. The FlipView functionality is still there though. What am I doing wrong?

XAML.

<FlipView x:Name="flpView" Grid.Row="1" Margin="10, 10, 10, 10">
    <Image x:Name="images" Stretch="UniformToFill" />
</FlipView>

代码背后.

public async Task flipviewload()
{
    // Add code to perform some action here.
    Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
    openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

    // Filter to include a sample subset of file types.
    openPicker.FileTypeFilter.Clear();
    openPicker.FileTypeFilter.Add(".bmp");
    openPicker.FileTypeFilter.Add(".png");
    openPicker.FileTypeFilter.Add(".jpeg");
    openPicker.FileTypeFilter.Add(".jpg");
    var files = await openPicker.PickMultipleFilesAsync();

    var images = new List<BitmapImage>();
    if (files != null)
    {
        //foreach (StorageFile Images in files)
        foreach (var file in files)
        {
            Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            using (Windows.Storage.Streams.IRandomAccessStream filestream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                BitmapImage bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(fileStream);
                //Images.Source = bitmapImage;
                images.Add(bitmapImage);
            }
        }
    }
    flpView.ItemsSource = images;
}

我还在我的公共 MainPage();

推荐答案

你得到这个结果是因为默认渲染在项目上调用 ToString(),它打印出类的名称.如果你想显示图像,你必须提供一个 ItemTemplate:

You get this result because default rendering calls ToString() on the item, which prints the name of the class. If you want to display the image you have to supply an ItemTemplate:

<FlipView x:Name="flpView" Grid.Row="1" Margin="10, 10, 10, 10">
    <FlipView.ItemTemplate>
        <DataTemplate>
            <Image Stretch="UniformToFill" Source="{Binding}" />
        </DataTemplate>
    </FlipView.ItemTemplate>
</FlipView>

这篇关于为什么我的翻页视图没有显示任何图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆