質問

Cannot get wpf project to reconise FolderBrowserDialog

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

 private void Button_Click_1(object sender, RoutedEventArgs e)
    {

        FolderBrowserDialog browse = new FolderBrowserDialog();
    }

type or name space FolderBrowserDialog could not be found???

役に立ちましたか?

解決

You will need to add reference to the assembly System.Windows.Forms before you can use the dialog in wpf. (Right click on project and select add reference)

他のヒント

If your project is a WPF .Net Core 3.1 then you have to add the following tag to the project file :-

<UseWindowsForms>true</UseWindowsForms>

My project file looks like this with this line in:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>   <<<<-----
  </PropertyGroup>
</Project>

After adding this line, save and clean the existing solution build and then rebuild it. This sorted the issue for me...oh don't forget to also add the "using" to your code file where you using the folder selection method:

using System.Windows.Forms;

A console application does not automatically add a reference to System.Windows.Forms.dll.

Right-click your project in Solution Explorer and select Add reference... and then find System.Windows.Forms and add it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top