如何在 .NET Core 3.0 中为 WPF 应用程序引用 System.Windows.Forms? [英] How to reference System.Windows.Forms in .NET Core 3.0 for WPF apps?

查看:41
本文介绍了如何在 .NET Core 3.0 中为 WPF 应用程序引用 System.Windows.Forms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的 WPF 桌面应用程序从 .NET Framework 迁移到 Core 3.0.我正在使用 System.Windows.Forms.FolderBrowserDialog() 并且我现在被困在如何将此引用添加到 Core 项目上.没有System.Windows.Forms"NuGet 包可用,有吗?有没有其他方法可以在 Core 中显示 FolderBrowserDialog?

I'm migrating my WPF desktop app from .NET Framework to Core 3.0. I was using System.Windows.Forms.FolderBrowserDialog() and I'm now stuck on how to add this reference to the Core project. There is no "System.Windows.Forms" NuGet package available, is there? Is there any alternative way to display the FolderBrowserDialog in Core?

更新

我使用默认模板创建了 Core 项目,然后将 .cs 和 .xaml 文件复制并粘贴到其中..csproj 文件如下所示:

I created the Core project using the default template and then copied and pasted .cs and .xaml files into it. The .csproj file looks like this:

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

推荐答案

你需要给 csproj 添加一个额外的开关:

You need to add to csproj an additional switch:

<UseWindowsForms>true</UseWindowsForms>

将其添加到 UseWpf 下方.然后尝试重建.在此之后,您应该能够使用 Forms 命名空间.

Add it below UseWpf. Then try rebuild. After this, you should be able to use Forms namespace.

这篇关于如何在 .NET Core 3.0 中为 WPF 应用程序引用 System.Windows.Forms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆