首页 > 解决方案 > 如何为多个文件夹(或文件)选择器配置对话框?

问题描述

我正在使用这个库https://github.com/augustoproiete/ookii-dialogs-wpf进行对话演示。

我正在使用这样的对话框来选择单个文件夹

        private void Btn_path_to_save_processed_clip_folder_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog
            {
                Description = "Select where to save processed clip folder",
                SelectedPath = m_TbClipSaveDirectory,
                UseDescriptionForTitle = true
            };

            if (dialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault())
            {
                m_TbClipSaveDirectory = dialog.SelectedPath;
            }
        }

问题是 - 是否可以一次选择几个文件夹?

或者也许其他一些方式?

标签: c#

解决方案


最终我用 NuGet 做到了

1)右键单击项目->管理NuGet包->在浏览选项卡中填充WindowsAPICodePack-Shell并设置为所需的包

2) 创建对话框

using var dialog = new CommonOpenFileDialog
{
    IsFolderPicker = true,
    Multiselect = true
};

在这里您可以看到两个设置IsFolderPicker- 为了只选择文件夹而不是文件和Multiselect- 用于多选

最终结果

if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
    var folders = dialog.FileNames;
    MessageBox.Show(string.Join("\n", folders));
}

结果是:

结果


推荐阅读