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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM