First time I'm implementing a FolderBrowserDialog in WPF and I'm not loving it one bit...
Aside from the issues I had figuring out that Windows.Forms wasn't referenced in my project, now I'm having trouble trying to see what the DialogResult return value is...
With an OpenFileDialog, in the past I've done it thusly:
OpenFileDialog ofd = new OpenFileDialog();
Nullable<bool> result = ofd.ShowDialog();
if (result == true)
{
// all went well, carry on and do your thing here
}
Unfortunately, I'm now getting errors with this saying something about conversions from type DialogResult to bool and whatever have you.
Can't seem to find anything on how to complete this step in using the dialog in WPF, can anyone shed some light?
Thanks in advance!
EDIT
Here's my code as amended without the type conversion error. I'm not sure what value to check result
against. Typically I'd use DialogResult.OK
except that doesn't appear as a valid value here.
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
if (cmbTemplate.SelectedItem == "Blockbusters")
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
//
// ERROR: 'System.Nullable<bool>' does not contain a definition for 'OK'
// and no extention method 'OK' accepting a first argument of type
// 'System.Nullable<bool>' could be found.
//
if (result == DialogResult.OK)
{
txtSource.Text = fbd.SelectedPath;
}
}
}
Dialog
does not return nullable bool like the WPF dialogs do, butDialogResult
. Just a hint. :) – Jojo