目前我可以选择多个文件,但是当我点击打开时,未显示所选图像。相反,“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();
答案 0 :(得分:2)
您会得到此结果,因为默认呈现会在项目上调用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>