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