[英]Can't find System.Windows.Media namespace?
我正在使用来自 3rd 方 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
对于Visual Studio 2017
在解决方案资源管理器中查找“参考”
右键单击“参考”
选择“添加参考...”
找到“Presentation.Core”列表并选中复选框
点击确定
您可以通过编辑项目文件更方便地添加 PresentationCore.dll。 将以下代码添加到您的 csproj 文件中:
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>
在您的解决方案资源管理器中,您现在应该会看到此框架已列出。 这样,您还可以参考 PresentationCore.dll 提供的类。
在我的情况下,我需要指定Platforms
标签 - 由于某种原因,它无法正常工作。
<PropertyGroup>
<!-- Must be here for this example, otherwise 'using System.Windows.Media.Media3D' does not work for intellisense -->
<Platforms>x64</Platforms>
</PropertyGroup>
视觉工作室 2019 v16.9.1。
我在CodeProject上找到了一个对我有用的答案。
打开您的项目文件,即*.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-windows
而不是net6.0
,并且还必须设置UseWpf
-flag。 然后你的*.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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.