c# - 命名空间 'Window' 中不存在类型或命名空间名称 'System.Windows'

标签 c# wpf namespaces extension-methods

我正在尝试为 WPF 窗口类编写一个扩展方法。我在我的解决方案中的类库项目中执行此操作,以便我可以在解决方案中的所有项目中使用它。

这是我的代码:

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.Forms 的引用,它们显示在解决方案资源管理器中项目中的引用下。

我做错了什么?

最佳答案

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

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

关于c# - 命名空间 'Window' 中不存在类型或命名空间名称 'System.Windows',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21621465/

相关文章:

c# - 使用 Linq 对 Gridview 进行分页

C# 在基类中创建派生类的实例

c# - 如何在Kotlin中创建等效于C#的新字符串

c# - 如何以这种方式调整 WPF 网格面板的大小?

c# - 从两个不同的 View 绑定(bind)到数据源。 MVVM、WPF

wpf - 在没有多点触控的开发机器上测试 Windows 7 多点触控?

c# - 选择选项下拉列表不显示所选选项

fortran - 编译不同的文件,其中函数和公共(public) block 具有相同的名称

configuration - 在高级模式下编译时对象被删除或部分折叠 - Google Closure Compiler

c++ - 定义全局命名空间