如何使 CommonOpenFileDialog 仅选择文件夹,但仍显示文件?
我正在使用 Microsoft 的 CommonOpenFileDialog 来允许用户选择文件夹,但出现对话框时看不到任何文件。当 IsFolderPicker
设置为 true 时,是否可以显示文件和文件夹?
我当前的代码如下所示
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
SelectedFolderPath = dialog.FileName;
}
I am using Microsoft's CommonOpenFileDialog to allow users to select a Folder, but no files are visible when the dialog comes up. Is it possible to show files as well as folders when IsFolderPicker
is set to true?
My current code looks like this
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
SelectedFolderPath = dialog.FileName;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我的脑海里,这就是我所做的
编辑:神圣的两年前蝙蝠侠!
似乎做了一些更改,下面的代码片段似乎可以完成这项工作
Off the top of my head, this is how I did it
EDIT: Holy 2 years ago Batman!
Seems like few changes were made, snippet below seems to do the job
不太确定是否可以以标准方式完成,但即使考虑到可以,请考虑UI。在一个地方查看当代文件夹和文件,但能够选择仅文件夹,在我看来并不是一个好的用户界面。恕我直言,这是更好、更“自然”的方式,让一个控件填充文件夹,而另一个控件(明显只读)仅填充必须加载的文件。
希望这有帮助。
Not very sure if it even possible to do in a standard way, but even considering that yes, think about UI. Seeing contemporary folders and files in one place, but be able to select only folders, doesn't seem to me a good UI. IMHO it's better, and more "natural" way, to have one control populated with folders, and another (clearly readonly) populated with only files that have to be loaded.
Hope this helps.
如果您希望用户仅选择一个文件夹,您是否考虑过使用FolderBrowserDialog?
If you want the user to select a folder only, have you considered using a FolderBrowserDialog?