tags:

views:

108

answers:

0

I try to use the FolderBrowserDialog from WPF like this:

public static bool BrowseFolder(out string folderName)
{
   using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
   {
        var result = dlg.ShowDialog();
        folderName = dlg.SelectedPath;
        return result == System.Windows.Forms.DialogResult.OK;
   }
}

When using "break on exception" in Visual Studio 2010 I get an Exception after closing the Dialog in the ShowDialog() call. I'm curious why this occurs.

Exception: Win32Exception
Message: The parameter is incorrect
Stacktrace: at MS.Win32.UnsafeNativeMethods.SetFocus(HandleRef hWnd)

Update
I also tried to set the parent explicitly, but the exception was thrown nonetheless.

var w = new System.Windows.Interop.WindowInteropHelper(parent);
System.Windows.Forms.IWin32Window i = new WindowWrapper(w.Handle);
result = dlg.ShowDialog(i);