How to reference System.Windows.Forms in .NET Core 3.0 for WPF apps?

陌路散爱 提交于 2020-11-26 07:03:11

问题


I'm migrating my WPF desktop app from .NET Framwork to Core 3.0. I was using System.Windows.Forms.FolderBrowserDialog() and am 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 the Core?

Update

I created the Core project using the default template and then copy 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>

回答1:


You need to add to csproj additional switch:

<UseWindowsForms>true</UseWindowsForms>

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




回答2:


Looks like it already exists: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.folderbrowserdialog?view=netcore-3.0

For other porting issues, you might want to use the Windows Compatibility Pack which is used to help port apps to .NET Core

There also might be some more information out there related to WPF and this issue, since it's been around for awhile. This might be helpful Select folder dialog WPF, and updated for .NET Core.

Good luck with your upgrade!



来源:https://stackoverflow.com/questions/58844785/how-to-reference-system-windows-forms-in-net-core-3-0-for-wpf-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!