【问题标题】:The type or namespace name 'Window' does not exist in the namespace 'System.Windows'命名空间“System.Windows”中不存在类型或命名空间名称“Window”
【发布时间】:2014-03-04 11:51:19
【问题描述】:

我正在尝试为 WPF Window 类编写扩展方法。我在我的解决方案的一个类库项目中这样做,这样我就可以在解决方案中的所有项目中使用它。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ExtensionMethods
{
    public static class MyExtensions
    {
        public static void ResizeToPrimaryScreenWorkingArea(this System.Windows.Window w)
        { 
        }
    }
}

当我尝试编译它时,我收到以下错误:

命名空间中不存在类型或命名空间名称“Window” 'System.Windows'

是的,我确实在我的类库项目中添加了对 System.Windows 和 System.Windows.Forms 的引用,它们显示在解决方案资源管理器的项目中的引用下。

我做错了什么?

【问题讨论】:

  • 你可以使用System.Windows.Window

标签: c# wpf namespaces extension-methods


【解决方案1】:

PresentationFramework.dll 引用添加到您的项目,它包含System.Windows 命名空间。

http://msdn.microsoft.com/es-es/library/system.windows.window(v=vs.110).aspx

【讨论】:

  • @JoeMjr2 您需要了解程序集的名称与其定义的任何类型的命名空间之间没有必要的关系。也没有要求在单个程序集中定义命名空间中的所有类型。答案中的文档链接指定了您尝试使用的类的程序集。
  • 汤姆,好点子!我从来没有这样想过。在大多数情况下,程序集名称和命名空间都会发生变化,但我想并非总是如此。从现在开始,我一定会在文档中检查该行!
猜你喜欢
  • 2022-01-11
  • 2016-02-11
  • 1970-01-01
  • 2012-06-19
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
相关资源
最近更新 更多