使用.net 6.0框架的WPF应用如何引用System.Windows.Forms这个dll

在.net 6.0的WPF应用中,想使用OpenFileDialog 这个类或者FolderBrowserDialog这个类,是无法找到System.Windows.Forms这个dll引用的,即使从系统C盘里搜索到System.Windows.Forms.dll放到项目里,也会出现异常,而无法识别WPF自带的一些初始化方法。

OpenFileDialog还好,因为他有两个命名空间都有它,一个是Microsoft.Win32,一个是System.Windows.Forms,无法引用System.Windows.Forms还可以退而求其次使用 using Microsoft.Win32;

以前的.net框架直接在Visual Studio项目->引用->右键->添加引用,可以直接方便的找到System.Windows.Forms.dll,但是.net 6.0不可以。经过一番搜索,终于在

Is it possible to use FolderBrowserDialog in a WPF Net 6 application?

找到解决方案

解决方案

<UseWindowsForms>true</UseWindowsForms>

放置的位置是,【项目名】.csproj文件,在Visual Studio 2022 里双击项目名可以打开这个文件。

 <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
    <AssemblyVersion>1.0.1</AssemblyVersion>
    <FileVersion>1.0.1.0</FileVersion>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

希望对你有所帮助,天下程序员是一家。文章来源地址https://uudwc.com/A/Z4kPm

原文地址:https://blog.csdn.net/YUNAN_ZHANG/article/details/124689596

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年06月28日 18:15
下一篇 2023年06月28日 18:15