当前位置:网站首页>WPF 选择文件夹

WPF 选择文件夹

2022-06-21 20:41:00 zLulus

效果如图
20201214_154224

使用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打开文件对话框(详解)

原网站

版权声明
本文为[zLulus]所创,转载请带上原文链接,感谢
https://blog.csdn.net/sinat_23050697/article/details/111096158