Why is my flipview not showing any pictures?

醉酒当歌 提交于 2019-12-11 06:59:43

问题


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>

Behind code.

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;
}

I also added Task foo = flipviewload(); in my public MainPage();


回答1:


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>


来源:https://stackoverflow.com/questions/19852459/why-is-my-flipview-not-showing-any-pictures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!