• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

使用.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>
希望对你有所帮助,天下程序员是一家。
————————————————
版权声明:本文为CSDN博主「Zhang_Yunan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/YUNAN_ZHANG/article/details/124689596

posted on 2022-12-08 20:27  gisai  阅读(1049)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3