无法识别文件夹浏览器对话框

Jed*_*d I 2 c# wpf folderbrowserdialog

无法让 wpf 项目重新识别FolderBrowserDialog

using System.Windows.Forms.Integration;
using System.Windows.Forms; 

 private void Button_Click_1(object sender, RoutedEventArgs e)
    {

        FolderBrowserDialog browse = new FolderBrowserDialog();
    }
Run Code Online (Sandbox Code Playgroud)

无法找到类型或名称空间FolderBrowserDialog???

小智 6

如果您的项目是 WPF .Net Core 3.1,那么您必须将以下标记添加到项目文件中:-

<UseWindowsForms>true</UseWindowsForms>
Run Code Online (Sandbox Code Playgroud)

我的项目文件如下所示,其中包含以下行:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>   <<<<-----
  </PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

添加此行后,保存并清理现有的解决方案构建,然后重建它。这为我解决了问题...哦,不要忘记将“using”添加到使用文件夹选择方法的代码文件中:

using System.Windows.Forms;
Run Code Online (Sandbox Code Playgroud)