找不到System.Windows.Media namepspace?

时间:2010-06-30 23:37:11

标签: c# .net namespaces

我正在使用第三方API中具有类型System.Windows.Media.ImageSource属性的对象,但我似乎无法在任何地方找到System.Windows.Media命名空间。如果我尝试添加对项目的引用,我在选项列表中看不到System.Windows.Media。我的项目也是针对.Net 3.5。

为了能够访问此命名空间,我还需要做些什么吗?

6 个答案:

答案 0 :(得分:79)

您应该添加对PresentationCore.dll的引用。

答案 1 :(得分:53)

System.Windows.Media.Imaging命名空间是PresentationCore.dll的一部分(如果您使用的是Visual Studio 2008,则WPF应用程序模板将自动添加此引用)。请注意,此命名空间不是WIC库的直接包装,尽管大部分更常见的用途仍然可用,并且这些映射到WIC版本的方式相对明显。有关此命名空间中的类的更多信息,请查看

http://msdn2.microsoft.com/en-us/library/system.windows.media.imaging.aspx

答案 2 :(得分:31)

PresentationCore.dll添加到您的参考文献中。这个dll网址在我的电脑上 - C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll

答案 3 :(得分:8)

对于 Visual Studio 2017

  

在解决方案资源管理器中查找“参考”

     

右键点击“参考”

     

选择“添加参考...”

     

找到“Presentation.Core”列表并勾选复选框

     

单击“确定”

答案 4 :(得分:3)

您可以通过编辑项目文件更方便地添加 PresentationCore.dll。将以下代码添加到您的 csproj 文件中:

<ItemGroup>
   <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
</ItemGroup>

在您的解决方案资源管理器中,您现在应该看到列出的这个框架。这样,您还可以引用 PresentationCore.dll 提供的类。

答案 5 :(得分:0)

我的情况是我需要指定 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。