VistaFolderBrowserDialog: Set InitialDirectory (not SelectedPath)
The VistaFolderBrowserDialog does not have an InitialDirectory property (like the open/save file variants do). The SelectedPath property sounds similar, but actually navigates to the parent directory and sets the given directory name as input for the textbox at the bottom.
Unless (hidden feature) you append a trailing backslash or slash. In that case, the dialog opens in the given path and nothing is selected.
I guess this only works because Path.GetDirectoryName(..) is tricked into a different result here: https://github.com/augustoproiete/ookii-dialogs-wpf/blob/d157189c795d4fdb500662bde8ad328d7d3eb602/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs#L280-L290
Whatever the implementation details, it would be good to have an explicit API that allows to set the initial directory.
Additional remarks:
Path.DirectorySeparatorChar(backslash) worksPath.AltDirectorySeparatorChar(slash) works, too but I'm on windows 10. Not sure if that makes any difference. My code looks like this for now:
string initialDirectory = string.IsNullOrEmpty(dir)
|| dir[dir.Length - 1] == Path.DirectorySeparatorChar
|| dir[dir.Length - 1] == Path.AltDirectorySeparatorChar
? dir
: dir + Path.DirectorySeparatorChar;
I've created a PR and tried to match your coding style. Feel free to change the style.
@augustoproiete did you have the time to look at my PR? The change is small and does not change / break existing code.
Hey @nzain thanks for the nudge. I looked at the code and in principle looks great. I'll set aside some time this week to run a few tests and get this merged in.
Did you run into problems? I'm willing to help!
I believe this is same behaviour utilised by the WinForms FolderBrowserDialog. So I reckon this is default behaviour for these type of selectors, and hence, would leave it as it is to avoid confusions.