我尝试像这样使用WPF中的FolderBrowserDialog:
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;
}
}
在使用Visual Studio 2010中的“断点异常”时,关闭ShowDialog()调用中的对话框后会出现异常。我很想知道这是为什么。
异常:Win32Exception
消息:参数不正确
堆栈跟踪: 在MS.Win32.UnsafeNativeMethods.SetFocus(HandleRef hWnd)
更新
我还尝试了显式设置父级,但仍然抛出了异常。
var w = new System.Windows.Interop.WindowInteropHelper(parent);
System.Windows.Forms.IWin32Window i = new WindowWrapper(w.Handle);
result = dlg.ShowDialog(i);