[英]Show files in folder while using FolderPicker
Is there any possible way to show the files in the folders when using FolderPicker
? 使用
FolderPicker
时是否有可能显示文件夹中的文件?
Code : 代码:
FolderPicker folderPicker = new FolderPicker();
folderPicker.ViewMode = PickerViewMode.Thumbnail;
folderPicker.SuggestedStartLocation = PickerLocationId.ComputerFolder;
folderPicker.FileTypeFilter.Add("*");
return await folderPicker.PickSingleFolderAsync();
If you use the WindowsAPICodepack, you can do it like so: 如果您使用WindowsAPICodepack,您可以这样做:
var openFolder = new CommonOpenFileDialog();
openFolder.AllowNonFileSystemItems = true;
openFolder.Multiselect = true;
openFolder.IsFolderPicker = true;
openFolder.Title = "Select folders.";
if (openFolder.ShowDialog() != CommonFileDialogResult.Ok)
{
MessageBox.Show("No folder selected.");
return;
}
// get all the directories in selected directory
var dirs = openFolder.FileNames.ToArray();
However if you're using just Windows.Storage.Pickers
, the code you've provided is the example given on the Microsoft docs ( https://docs.microsoft.com/en-us/uwp/api/windows.storage.pickers.folderpicker ), so I'm not too sure why that doesn't work. 但是,如果您只使用
Windows.Storage.Pickers
,则您提供的代码是Microsoft文档( https://docs.microsoft.com/en-us/uwp/api/windows.storage)上给出的示例。 pickers.folderpicker ),所以我不太清楚为什么这不起作用。
For the built-in FolderPicker, it's impossible. 对于内置的FolderPicker,这是不可能的。 You could call the 'StorageFolder.GetFilesAsync' method to get the files in the current folder.
您可以调用“StorageFolder.GetFilesAsync”方法来获取当前文件夹中的文件。
FolderPicker folderPicker = new FolderPicker();
folderPicker.ViewMode = PickerViewMode.List;
folderPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
folderPicker.FileTypeFilter.Add("*");
var folder = await folderPicker.PickSingleFolderAsync();
foreach (var files in await folder.GetFilesAsync())
{
Debug.WriteLine(files.DisplayName);
}
If you want to show these files on the UI, you could choose some list controls to show them. 如果要在UI上显示这些文件,可以选择一些列表控件来显示它们。 For example, List view and grid view .
例如, 列表视图和网格视图 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.