我尝试使用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;
}
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2010中使用"break on exception"时,在ShowDialog()调用中关闭Dialog后会出现异常.我很好奇为什么会这样.
异常:Win32Exception
消息:参数不正确
Stacktrace:at 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);
Run Code Online (Sandbox Code Playgroud) 我正在使用AvalonDock 2.0,当我打开一个dock容器时,在调试模式下应用程序崩溃(它在没有调试的情况下运行时工作正常).我得到以下异常:
WindowsBase.dll中发生了未处理的"System.ComponentModel.Win32Exception"类型异常
附加信息:操作成功完成
我遇到了这个答案,建议取消选中"例外设置"中的框.有线的事情是它第一次使用它.但它不再存在了.我试过其他机器也不行.任何有关如何解决此问题的建议.
Avalon代码(第5行引发的异常)
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
if (msg == Win32Helper.WM_WINDOWPOSCHANGING) {
if (_internalHost_ContentRendered) {
// the below line throw the exception
Win32Helper.SetWindowPos(_internalHwndSource.Handle, Win32Helper.HWND_TOP, 0, 0, 0, 0, Win32Helper.SetWindowPosFlags.IgnoreMove | Win32Helper.SetWindowPosFlags.IgnoreResize);
}
}
return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
}
Run Code Online (Sandbox Code Playgroud)