本文介绍了如何在 .Net Core 中引用 System.Windows 命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WPF(.Net 框架)开发人员很长时间了,我终于第一次涉足 .Net Core.我目前正在尝试将一个小型 v4.7.2 WPF 应用程序转换为 .Net Core 3.1.该解决方案包含一个 WPF 应用程序项目和一个类库项目,每个项目只有少数几个类,因此我决定创建一个包含 WPF 应用程序和类库项目(均为 .Net Core 3.1)的新解决方案会更容易,然后从原始解决方案中复制 cs 和 xaml 文件.然而,我似乎在第一个障碍...

I'm a long time WPF (.Net Framework) developer finally dipping my toes into .Net Core for the first time. I'm currently trying to convert a small v4.7.2 WPF application to .Net Core 3.1. The solution contains a WPF app project and a class library project, with only a handful of classes each, so I decided it would be easier to create a new solution containing a WPF app and class library project (both .Net Core 3.1), then copy the cs and xaml files from the original solution. However I seem to be falling at the first hurdle...

许多类使用来自 System.Windows 命名空间(以及 System.Windows.MediaSystem.Windows.Controls、等等).这些在 WPF 应用程序项目中解决得很好,但在类库中解决不了.我注意到 WPF 应用程序项目引用了框架Microsoft.WindowsDesktop.App.Wpf",但类库项目没有,我认为这是我的问题.但是,我终生无法弄清楚如何将此框架添加到项目中.我该怎么做?!

Many of the classes use types from the System.Windows namespace (and System.Windows.Media, System.Windows.Controls, etc). These resolve fine in the WPF app project but not the class library. I've noticed the WPF app project has a reference to the framework "Microsoft.WindowsDesktop.App.Wpf", but the class library project doesn't, which I assume is my problem. However I can't for the life of me figure out how to add this framework into the project. How do I do it?!

我在其他地方看到过将 true</UseWPF> 添加到类库 csproj 文件的解决方案,但这没有效果.

I've seen solutions elsewhere of adding <UseWPF>true</UseWPF> to the class lib csproj file, but this has no effect.

推荐答案

像往常一样,我一发布问题就找到了答案.我还必须将 csproj 文件中的 SDK 更改为:

As usual, no sooner do I post the question than I find the answer. I also had to change the SDK in the csproj file to:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

这篇关于如何在 .Net Core 中引用 System.Windows 命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:41