在WPF中,如何使用标准对话框选择一个目录?

4

我需要用户选择一个目录,而不是文件。如何使用Microsoft.Win32.OpenFileDialog(或任何其他组件)来实现?

我在VisualStudio 2010(.net 4.0)中使用WPF4.0。

2个回答

2

使用 System.Windows.Forms.FolderBrowserDialog:

var dlg = new System.Windows.Forms.FolderBrowserDialog();
dlg.ShowNewFolderButton = true; //if you want new folders as well
dlg.SelectedPath = someStartPath; //where to start
if( dlg.ShowDialog() == DialogResult.OK )
{
  //ok user selected something
  DoStuffWith( dlg.SelectedPath );
}

0

你可以通过Windows API Code Pack访问到许多来自Win32生态系统的标准对话框和控件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接