.net 在WPF中使用OpenFileDialog时没有文件的文件夹路径?

.net 在WPF中使用OpenFileDialog时没有文件的文件夹路径?,.net,wpf,c#-4.0,wpf-controls,wpf-4.0,.net,Wpf,C# 4.0,Wpf Controls,Wpf 4.0,如果文件夹中没有文件,如何使用WPF中的OpenFileDialog类获取文件夹路径 { Microsoft.Win32.OpenFileDialog dlgObjDest = new Microsoft.Win32.OpenFileDialog(); dlgObjDest.Multiselect = true; dlgObjDest.DefaultExt = ".*"; dlgObjDest.InitialDirectory = "c:";

如果文件夹中没有文件,如何使用WPF中的OpenFileDialog类获取文件夹路径

{
      Microsoft.Win32.OpenFileDialog dlgObjDest = new Microsoft.Win32.OpenFileDialog();
      dlgObjDest.Multiselect = true;
      dlgObjDest.DefaultExt = ".*";
      dlgObjDest.InitialDirectory = "c:";
      if (dlgObjDest.ShowDialog() == true)
      {
          txtDestTesting.Text = System.IO.Path.GetDirectoryName(dlgObjDest.FileName);
      }
}

但是当没有可选择的文件时,它无法获取文件夹路径如果没有选择任何文件,
ShowDialog()
将无法返回
true

如果先将
OpenFileDialog
CheckFileExists
属性设置为
true
,则用户可以输入不存在的文件名,然后您将获得文件路径

我认为您需要的是一个
FolderBrowserDialog
,它不是WPF内置的,但可以像在这个库中一样实现: