Home > Blockchain >  How to add Windows.Forms framework to WPF project in Visual Studio
How to add Windows.Forms framework to WPF project in Visual Studio

Time:06-22

I"m a complete noob in Visual Studio. I'm trying to write a simple app using WPF. I need a dialog that would pick a folder. I know that WPF doesn't have one, and I need to use Windows.Forms with their FolderBrowserDialog. I need to add Widnows.Forms framework to references so that I could say using System.Windows.Forms; and then just do this dialog. However when I'm trying to follow the instructions, I do not see any Windows.Forms here, except for what's on the image. And even if I add those, it still doesn't take using System.Windows.Forms; What should I do? This is References MAnager for the project

CodePudding user response:

  1. Create a WPF Application project named HostingWfInWpf.
  2. add references to the following assemblies.
  3. Open MainWindow.
  4. Name the Grid element grid1.
  5. In the Design view or XAML view, select the Window element.
  6. In the Properties window, click the Events tab.
  7. Double-click the Loaded event.

CodePudding user response:

  1. First create a .Net6 Wpf project
  2. Double-click the project to enter csproj and manually add the following code:
<UseWindowsForms>true</UseWindowsForms>

enter image description here

  1. Manually enter the following new enter image description here

    1. call it
    private void Button_Click(object sender, RoutedEventArgs e)
    {
      using FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
      {
        folderBrowserDialog.ShowDialog();
      }
    }
    
    1. You can also go to Property->Application->General->Windows Forms->Enable Windows Forms for this Project in the .net6 project.

    enter image description here

  • Related