目前,我可以选择多个文件,但是当我单击“打开”时,未显示所选图像。相反,“ Windows.ui.xaml.media.imaging.bitmapimage”作为文本出现。这 FlipView 功能仍然存在。我究竟做错了什么?

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

我还添加了 Task foo = flipviewload(); 在我的公共场合 MainPage();

有帮助吗?

解决方案

您会得到此结果,因为默认渲染调用 ToString() 在打印班级名称的项目上。如果要显示图像,则必须提供 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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top