2014-02-07 39 views
2

我试图写一个WPF窗口类的扩展方法。我在我的解决方案中的类库项目中执行此操作,以便我可以在解决方案的所有项目中使用它。类型或命名空间名称“窗口”不存在命名空间存在“System.Windows”

这里是我的代码:

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) 
     { 
     } 
    } 
} 

当我尝试编译,我得到以下错误:

The type or namespace name 'Window' does not exist in the namespace 'System.Windows'

是的,我也引用添加System.Windows和System.Windows 。我的类库项目中的表单,它们显示在解决方案资源管理器中项目的参考。

我在做什么错?

回答

5

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

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

+0

工作完美,谢谢! – JoeMjr2

+0

欢迎您:) –

+1

@ JoeMjr2您需要了解程序集的名称与其定义的任何类型的名称空间之间没有必需的关系。也不要求在一个程序集中定义名称空间中的所有类型。答案中的文档链接指定您尝试使用的类的程序集。 –

相关问题