我正在使用一个第三方API中的对象,该对象具有类型为System.Windows.Media.ImageSource
的属性,但是我似乎找不到任何关于System.Windows.Media
命名空间的信息。如果我尝试在项目中添加引用,我在选项列表中看不到System.Windows.Media
。我的项目也针对.NET 3.5。
我需要做些什么才能访问这个命名空间呢?
我正在使用一个第三方API中的对象,该对象具有类型为System.Windows.Media.ImageSource
的属性,但是我似乎找不到任何关于System.Windows.Media
命名空间的信息。如果我尝试在项目中添加引用,我在选项列表中看不到System.Windows.Media
。我的项目也针对.NET 3.5。
我需要做些什么才能访问这个命名空间呢?
你需要添加对PresentationCore.dll的引用。
System.Windows.Media.Imaging
命名空间是 PresentationCore.dll 的一部分(如果您正在使用 Visual Studio 2008,则 WPF 应用程序模板将自动添加此引用)。请注意,尽管许多常见用法仍然可用,并且它们如何映射到 WIC 版本相对明显,但该命名空间不是 WIC 库的直接包装。有关此命名空间中的类的更多信息,请查阅http://msdn2.microsoft.com/en-us/library/system.windows.media.imaging.aspx。
将PresentationCore.dll
添加到您的引用中。此dll在我的计算机上的URL为- C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll
通过编辑项目文件,您可以更方便地添加PresentationCore.dll。将以下代码添加到您的csproj文件中:
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>
在您的解决方案资源管理器中,您现在应该看到列出了此框架。有了这个,您还可以引用由PresentationCore.dll提供的类。
针对 Visual Studio 2017
在“解决方案资源管理器”中找到“引用”
右键单击“引用”
选择“添加引用...”
找到“Presentation.Core”列表并选中复选框
点击确定
WindowsBase.dll
。 - Andrei Krasutski*.csproj
文件,以文本文件的方式进行编辑。如果像我一样,你的目标是net6.0
,你会看到类似下面这样的内容:<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>WinExe</OutputType>
</PropertyGroup>
</Project>
net6.0
更改为net6.0-windows
,并且还必须设置UseWpf
标志。然后你的*.csproj
文件应该像这样:<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWpf>true</UseWpf>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>WinExe</OutputType>
</PropertyGroup>
</Project>
Platforms
标签 - 出于某种原因,否则它不起作用。 <PropertyGroup>
<!-- Must be here for this example, otherwise 'using System.Windows.Media.Media3D' does not work for intellisense -->
<Platforms>x64</Platforms>
</PropertyGroup>
Visual Studio 2019 v16.9.1。