WPF 选择文件夹

效果如图

使用FolderBrowserDialog

System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
System.Windows.Forms.DialogResult result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.Cancel)
{
    return;
}
selectFolrderPathTextBlock.Text = dialog.SelectedPath.Trim();

使用FolderBrowserDialog

//引用WindowsAPICodePack
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
    selectFolrderPathTextBlock.Text = dialog.FileName;
}

示例代码

SelectFolder

参考资料

OpenFileDialog In WPF
C# OPENFILEDIALOG打开文件对话框(详解)

原文地址:https://www.cnblogs.com/Lulus/p/14133673.html