

上面的代码如果是在WinForm程序里面,是没有问题的。但是如果在WPF里面则编译不通过,错误描述是
The best overloaded method match for 'System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)' has some invalid arguments。
这是因为WPF的窗口不是继承IWin32Window接口的,继承的是System.Windows.IWindowService接口。如果想在WPF程序里面使用FolderBrowserDialog,可以象下面这么写:

















