在wpf中,如何使用标准对话框选择目录

时间:2011-11-09 11:54:45

标签: .net wpf visual-studio-2010

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

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

2 个答案:

答案 0 :(得分: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 );
}

答案 1 :(得分:0)

您可以通过Windows API Code Pack访问Win32生态系统中的那个以及许多其他标准对话框和控件。