Skip to content

Commit de0e029

Browse files
Add sample for using Folder Browser with multiselect
Co-authored-by: "C. Augusto Proiete" <[email protected]>
1 parent 0583a9c commit de0e029

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

sample/Ookii.Dialogs.Wpf.Sample/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ComboBoxItem>Progress Dialog</ComboBoxItem>
1717
<ComboBoxItem>Credential Dialog</ComboBoxItem>
1818
<ComboBoxItem>Vista-style Folder Browser Dialog</ComboBoxItem>
19+
<ComboBoxItem>Vista-style Folder Browser Dialog (Select Multiple)</ComboBoxItem>
1920
<ComboBoxItem>Vista-style Open File Dialog</ComboBoxItem>
2021
<ComboBoxItem>Vista-style Save File Dialog</ComboBoxItem>
2122
</ComboBox.Items>

sample/Ookii.Dialogs.Wpf.Sample/MainWindow.xaml.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ private void _showDialogButton_Click(object sender, RoutedEventArgs e)
6060
ShowFolderBrowserDialog();
6161
break;
6262
case 5:
63-
ShowOpenFileDialog();
63+
ShowFolderBrowserDialogSelectMultiple();
6464
break;
6565
case 6:
66+
ShowOpenFileDialog();
67+
break;
68+
case 7:
6669
ShowSaveFileDialog();
6770
break;
6871
}
@@ -162,13 +165,46 @@ private void ShowCredentialDialog()
162165

163166
private void ShowFolderBrowserDialog()
164167
{
165-
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();
168+
var dialog = new VistaFolderBrowserDialog();
166169
dialog.Description = "Please select a folder.";
167170
dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
168-
if( !VistaFolderBrowserDialog.IsVistaFolderDialogSupported )
171+
172+
if (!VistaFolderBrowserDialog.IsVistaFolderDialogSupported)
173+
{
169174
MessageBox.Show(this, "Because you are not using Windows Vista or later, the regular folder browser dialog will be used. Please use Windows Vista to see the new dialog.", "Sample folder browser dialog");
170-
if( (bool)dialog.ShowDialog(this) )
171-
MessageBox.Show(this, "The selected folder was: " + dialog.SelectedPath, "Sample folder browser dialog");
175+
}
176+
177+
if ((bool)dialog.ShowDialog(this))
178+
{
179+
MessageBox.Show(this, $"The selected folder was:{Environment.NewLine}{dialog.SelectedPath}", "Sample folder browser dialog");
180+
}
181+
}
182+
183+
private void ShowFolderBrowserDialogSelectMultiple()
184+
{
185+
var dialog = new VistaFolderBrowserDialog();
186+
dialog.Multiselect = true;
187+
dialog.Description = "Please select a folder.";
188+
dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
189+
190+
if (!VistaFolderBrowserDialog.IsVistaFolderDialogSupported)
191+
{
192+
MessageBox.Show(this, "Because you are not using Windows Vista or later, the regular folder browser dialog will be used. Please use Windows Vista to see the new dialog.", "Sample folder browser dialog");
193+
}
194+
195+
if ((bool)dialog.ShowDialog(this))
196+
{
197+
var selectedPaths = dialog.SelectedPaths;
198+
199+
if (selectedPaths.Length == 1)
200+
{
201+
MessageBox.Show(this, $"The selected folder was:{Environment.NewLine}{selectedPaths[0]}", "Sample folder browser dialog");
202+
}
203+
else
204+
{
205+
MessageBox.Show(this, $"The selected folders were:{Environment.NewLine}{string.Join(Environment.NewLine, selectedPaths)}", "Sample folder browser dialog");
206+
}
207+
}
172208
}
173209

174210
private void ShowOpenFileDialog()

0 commit comments

Comments
 (0)