C# 在Windows 8应用程序中显示动态图片库?
我目前正在开发一个简单的Windows8应用程序,作为更复杂的概念的基本证明 目前,我有一个文本框和两个按钮。一个按钮允许您选择文件夹(填充“我的文本框”中的文件夹路径) 另一个按钮应返回当前选定文件夹中前5个图像的绝对路径,但我在Win8应用程序中使用C# 在Windows 8应用程序中显示动态图片库?,c#,windows,xaml,windows-8,windows-applications,C#,Windows,Xaml,Windows 8,Windows Applications,我目前正在开发一个简单的Windows8应用程序,作为更复杂的概念的基本证明 目前,我有一个文本框和两个按钮。一个按钮允许您选择文件夹(填充“我的文本框”中的文件夹路径) 另一个按钮应返回当前选定文件夹中前5个图像的绝对路径,但我在Win8应用程序中使用FileOpenPicker时遇到一些问题 我想做的是,当点击这个按钮时,我不想返回图像的前5个路径,我想以这样的网格格式显示它们,只是不想向右扩展,而是像传统网站一样向下扩展 到目前为止,我所拥有的: XAML: <StackPanel
FileOpenPicker
时遇到一些问题
我想做的是,当点击这个按钮时,我不想返回图像的前5个路径,我想以这样的网格格式显示它们,只是不想向右扩展,而是像传统网站一样向下扩展
到目前为止,我所拥有的:
XAML:
<StackPanel Grid.Row="2" Margin="120,0,0,0">
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBox x:Name="pictureInput" HorizontalAlignment="Left" Grid.Row="2" TextWrapping="Wrap" Text="Select Image..." VerticalAlignment="Top" Width="300" Height="41" FontSize="24"/>
<Button Content="Browse" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" Height="41" Width="147" Click="Browse_Folder_Click"/>
<TextBlock x:Name="ImgThumbHere" Grid.Column="2" Width="540"/>
<Button Content="Find Images" HorizontalAlignment="Left" VerticalAlignment="Top" Height="90" Width="250" Click="Find_Images"/>
</StackPanel>
</StackPanel>
Xaml.CS:
//method to select folder :
private async void Browse_Folder_Click(object sender, RoutedEventArgs e)
{
string folderPath = "";
FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker();
// Create the picker object and set options
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
// Users expect to have a filtered view of their folders depending on the scenario.
// For example, when choosing a documents folder, restrict the filetypes to documents for your application.
folderPicker.FileTypeFilter.Add("*");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
if (folder.Path != "" && folder.Path != null)
{
folderPath = folder.Path;
}
else
{
folderPath = folder.Name;
}
}
else
{
throw new Exception("Folder path null.");
}
folderInput.Text = folderPath;
}
//attempt at method to select first 5 images of selected folder :
private async void Find_Images(object sender, RoutedEventArgs e)
{
string[] picturePath;
FileOpenPicker picPicker = new Windows.Storage.Pickers.FileOpenPicker();
picPicker.ViewMode = PickerViewMode.Thumbnail;
// Create the picker object and set options
picPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
// Users expect to have a filtered view of their folders depending on the scenario.
// For example, when choosing a documents folder, restrict the filetypes to documents for your application.
picPicker.FileTypeFilter.Add(".png");
picPicker.FileTypeFilter.Add(".jpg");
picPicker.FileTypeFilter.Add(".jpeg");
picPicker.FileTypeFilter.Add(".gif");
picPicker.FileTypeFilter.Add(".bmp");
for (int i = 0; i < 5; i++)
{
StorageFile file = picPicker.//What can be called here to return paths ?
if (file != null)
{
picturePath[i] = file.path;
}
else
{
throw new Exception("File path null.");
}
}
}
//选择文件夹的方法:
私有异步无效浏览\u文件夹\u单击(对象发送方,路由目标)
{
字符串folderPath=“”;
FolderPicker FolderPicker=新建Windows.Storage.Pickers.FolderPicker();
//创建选择器对象并设置选项
folderPicker.SuggestedStartLocation=Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
//用户希望根据场景对其文件夹进行筛选。
//例如,选择文档文件夹时,将文件类型限制为应用程序的文档。
folderPicker.FileTypeFilter.Add(“*”);
StorageFolder folder=等待folderPicker.PickSingleFolderAsync();
如果(文件夹!=null)
{
if(folder.Path!=“”&&folder.Path!=null)
{
folderPath=folder.Path;
}
其他的
{
folderPath=folder.Name;
}
}
其他的
{
抛出新异常(“文件夹路径为空”);
}
Text=folderPath;
}
//尝试使用方法选择选定文件夹的前5个图像:
专用异步void Find_映像(对象发送方、RoutedEventArgs e)
{
字符串[]图片路径;
FileOpenPicker-picPicker=新的Windows.Storage.Pickers.FileOpenPicker();
picPicker.ViewMode=PickerViewMode.缩略图;
//创建选择器对象并设置选项
picPicker.SuggestedStartLocation=Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
//用户希望根据场景对其文件夹进行筛选。
//例如,选择文档文件夹时,将文件类型限制为应用程序的文档。
picPicker.FileTypeFilter.Add(“.png”);
picPicker.FileTypeFilter.Add(“.jpg”);
picPicker.FileTypeFilter.Add(“.jpeg”);
picPicker.FileTypeFilter.Add(“.gif”);
picPicker.FileTypeFilter.Add(“.bmp”);
对于(int i=0;i<5;i++)
{
StorageFile file=picPicker//这里可以调用什么来返回路径?
如果(文件!=null)
{
picturePath[i]=file.path;
}
其他的
{
抛出新异常(“文件路径为空”);
}
}
}
谁能帮我解决这个问题
非常感谢。看看
问题是,根据设计,您仅限于:
- 访问本地存储
- 访问几个著名的存储位置
- 访问特定授予的位置