简体   繁体   English

如何在 Visual Studio 中将 Windows.Forms 框架添加到 WPF 项目

[英]How to add Windows.Forms framework to WPF project in Visual Studio

I"ma 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?我在 Visual Studio 中完全是菜鸟。我正在尝试使用 WPF 编写一个简单的应用程序。我需要一个可以选择文件夹的对话框。我知道 WPF 没有,我需要使用 Windows.Forms他们的 FolderBrowserDialog。我需要将 Widnows.Forms 框架添加到引用中,以便我可以说using System.Windows.Forms;然后执行此对话框。但是,当我尝试按照说明进行操作时,我看不到任何 Windows。这里的表格,除了图像上的内容。即使我添加了这些, using System.Windows.Forms;我该怎么办? 这是该项目的 References MANager

  1. First create a .Net6 Wpf project首先创建一个.Net6 Wpf项目
  2. Double-click the project to enter csproj and manually add the following code:双击工程进入csproj,手动添加如下代码:
<UseWindowsForms>true</UseWindowsForms>

在此处输入图像描述

  1. Manually enter the following new folderbrowserdialog code, and then use intellisense to automatically add using System.Windows.Forms;手动输入以下新建文件夹browserdialog代码,然后使用intellisense使用System.Windows.Forms自动添加; That's it (you can also add it manually)就是这样(你也可以手动添加)
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

在此处输入图像描述

  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.您也可以在 .net6 项目中转到Property -> Application -> General -> Windows Forms -> Enable Windows Forms for this Project

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 WPF 项目中删除 Windows.Forms 参考 - Can't Remove Windows.Forms reference from WPF Project 如何在Visual Studio 2015中将两个项目WinRT与Windows.Forms合并 - How to merge two projects WinRT with Windows.Forms in Visual Studio 2015 如何使用GUI在Visual Studio项目中而不是直接从Visual Studio添加和编译Windows窗体? - How to add and compile windows forms in Visual Studio project using a GUI, and not directly from Visual Studio? 使用 Windows 窗体和 .NET Framework 在 Visual Studio 中创建项目 - Creating a project in Visual Studio with Windows Forms and the .NET Framework 向Windows.Forms退出按钮添加功能? - Add functionality to Windows.Forms exit button? 无法将QuickTime控件添加到Visual Studio中的Windows窗体项目 - Unable to add QuickTime control to Windows Forms project in Visual Studio 如何本地化Windows.Forms .NET应用程序? - How to localize a Windows.Forms .NET application? 从 Windows.forms 打开时如何关闭用户控件 wpf - How do close the User control wpf when opened from a Windows.forms 在Windows.Forms中绘图 - Drawing in Windows.Forms 如何在 Visual Studio 2019 中添加对新 Windows Forms 项目的引用 - How do I add a Reference to a new Windows Forms Project in Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM