WPF选择文件夹对话框

发布时间:2019-10-30 15:37:50 作者:Potato 阅读量:2421

WPF的提供了选择文件对话框

但并没有提供选择文件夹的对话框。

解决方法1:
a、添加System.Windows.Forms的引用

b、引用命名空间,为避免类名冲突可以给命名空间别名

c、使用System.Windows.Forms命名空间下的FolderBrowserDialog类

WinForm.FolderBrowserDialog dialog = new WinForm.FolderBrowserDialog();
dialog.ShowDialog();
效果如下:

解决方法2:
a、打开程序包管理器控制台

b、安装WindowsAPICodePack-Shell包,使用Install-Package WindowsAPICodePack-Shell命令。

注意对应的项目

c、使用CommonOpenFileDialog类打开对话框

CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;//设置为选择文件夹
dialog.ShowDialog();

支付宝打赏 微信打赏

我要评论

Catfish(鲶鱼) Blog V 4.7.3