0

我正在寻找并打开文件夹对话框(wpf)。我得到了 wpf 的 Ookii 对话框,我使用了 VistaFolderBrowserDialog。(我不喜欢 Windows 窗体的 FolderBrowserDialog)。

我保存“最后打开的文件夹”。因此,下次用户打开此 VistaFolderBrowserDialog 时,初始文件夹是我保存的“最后一个”。

...
//Save the new actual folder
MyProject.ProgramConfigurationFile.Instance.OpenFolderPath = System.IO.Path.GetDirectoryName(folderDialog.SelectedPath);

VistaFolderBrowserDialog 具有属性 => RootFolder:

公共环境..::..SpecialFolder RootFolder { get; 放; 但它是一个 SpecialFolder 类型。

所以我正在寻找一种将我的 String OpenFolderPath 设置为 RootFolder 属性的方法。

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;
if ((bool)folderDialog.ShowDialog(this))
{
     //Get the last open folder saved (if exist).
     if(!String.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
     {
         folderDialog.RootFolder = Environment.SpecialFolder. //I would like to set OpenFolderPath
     }  
}

也欢迎使用其他文件夹浏览器。

非常感谢。

4

1 回答 1

0

I did not know before now Ookii dialogs, but after a little search and knowing how common Open Folder Dialog works i suggest that you set your lastOpenFolder to the SelectedPath property

folderDialog.SelectedPath = MyProject.ProgramConfigurationFile.Instance.OpenFolderPath;

But this must be done before folderDialog.ShowDialog(this) showing the dialog.

So it should look something like

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;

if(!string.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
    folderDialog.SelectedPath = myProject.ProgramConfigurationFile.Instance.OpenFolderPath;

if ((bool)folderDialog.ShowDialog(this))
{
    string newSelectedFolderPath = folderDialog.SelectedPath;
    // Use new folderPath
}

Let me know if this solves it.

I hope I was usefull.

于 2020-02-19T15:13:02.750 回答