我正在创建一个UWP App图片库,我想用一种方法上传一个图像列表,用一种方法将文件夹位置更改为multipes PivotItems
public async void precargar()
{
List<StackPanel> spanel = new List<StackPanel>();
IReadOnlyList<StorageFile> files = await Imagefolder.GetFilesAsync();
foreach (var item in files)
{
StackPanel stack = new StackPanel();
StorageItemThumbnail thumbnail = null;
try { thumbnail = await item.GetThumbnailAsync(ThumbnailMode.PicturesView); }
catch (Exception) { System.Diagnostics.Debug.WriteLine("esto es un error lo sentimos"); }
BitmapImage bi;
if (thumbnail == null)
{
bi = new BitmapImage(new Uri("ms-appx:///wallpaper/2.png"));
}
else
{
Stream stream = thumbnail.AsStream();
bi = new BitmapImage();
await bi.SetSourceAsync(stream.AsRandomAccessStream());
}
Image image = new Image() { Width = 300 };
image.Source = bi;
stack.Children.Add(image);
spanel.Add(stack);
}
Viewtiles.ItemsSource = spanel;
}
上面的代码以这种方式正常工作:我以这种方式使用它将它们加载到接口
public async void CargarFolders()
{
Imagefolder = await appInstalledFolder.GetFolderAsync(carpetas[0]);
precargar();
}
现在我想使用该代码以下列方式使用相同的代码加载其他图像列表:
public async void Naturaleza()
{
Imagefolder = await appInstalledFolder.GetFolderAsync(carpetas[1]);
precargar();
Naturals.ItemsSource = spanel;
}
但它不起作用。我该怎么做?
我认为您应该使用FlipView控件而不是枢轴控件来显示图像。因为FlipView控件具有触摸友好的前后移动选项。您可以将大量图像设置为FlipView控件。
请通过https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/flipview