在 .NET Core 中使用 System.Windows [英] Using System.Windows in .NET Core

查看:68
本文介绍了在 .NET Core 中使用 System.Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2019 中有一个项目,我要从 .NET Framework 4.6 迁移到 .NET Core 3.1.

I have a project in Visual Studio 2019 that I am migrating from .NET Framework 4.6 to .NET Core 3.1.

我使用 Microsoft 的指南来移植我的项目,此处描述.我运行了 Portability Analyzer 并显示,该项目是 100% 可移植的.

I used the guide from Microsoft to port my project, described here. I ran the Portability Analyzer and it showed, that the project is to 100% portable.

但是对 System.Windows 的所有依赖都不再起作用.例如,我使用 System.Windows.Rect.在官方文档中它清楚地表明它可用于 .NET Core 3.1.

But every dependency to System.Windows doesn't work anymore. For example I use System.Windows.Rect. In the official documentation it clearly states that it is available for .NET Core 3.1.

然而,在代码中,它用找不到类型或命名空间名称‘Rect’(您是否缺少 using 指令或程序集引用?)"来标记 Rect,并在顶部标记我的 using System.Windows 灰色并显示不需要使用指令".

In the code however it marks Rect with "The type or namespace name 'Rect' could not be found(are you missing a using directive or an assembly reference?)" and on the top it marks my using System.Windows grey with the message "Using directive is unnecessary".

此错误适用于我的代码中的许多内容,例如 System.Windows.ResourceDictionarySystem.Windows.Application.CurrentSystem.Windows.Point, ...

This error applies to many things in my code, like System.Windows.ResourceDictionary, System.Windows.Application.Current, System.Windows.Point, ...

因此,由于某些原因,我似乎无法使用 System.Windows,即使使用本身似乎工作正常.

So for some reasons it seems that I can't use System.Windows, even if the using itself seems to work fine.

我在 NuGet 包管理器中搜索了 System.Windows用谷歌搜索,但找不到任何东西.

I searched for System.Windows in the NuGet package manager and googled it, but couldn't find anything.

所以这是我的问题:如何在带有 Visual Studio 2019 的 .NET Core 3.1 项目中使用 System.Windows?我目前的猜测是,我需要手动包含程序集 WindowsBase.dll 但在我的安装目录 (C:Program Files (x86)Microsoft Visual Studio2019Professional) 我只能在 C:Program Files (x86)Microsoft Visual Studio2019ProfessionalCommon7IDEExtensionsMicrosoftLiveShareAgent 找到一个并且它没有这似乎是正确的.

So here is my question: How can I use System.Windows in a .NET Core 3.1 project with Visual Studio 2019? My guess at the moment is, that I need to manually include the assembly WindowsBase.dll but in my installation directory (C:Program Files (x86)Microsoft Visual Studio2019Professional) I can only find one at C:Program Files (x86)Microsoft Visual Studio2019ProfessionalCommon7IDEExtensionsMicrosoftLiveShareAgent and it doesn't seem to be the right one.

推荐答案

以下是使用 net5.0 的方法:

Here is how to do it with net5.0:

 <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

这篇关于在 .NET Core 中使用 System.Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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