2

我要疯了吗?或者它是编译器?

我有:

Window w = new Window();

当我尝试使用需要 a 的函数时,FrameworkElement编译器会抱怨:

无法从“System.Windows.Window”转换为“System.Windows.FrameworkElement”

当我尝试这样做w.Show()时,它会抱怨:

“System.Windows.Window”不包含“Show”的定义,并且找不到接受“System.Windows.Window”类型的第一个参数的扩展方法“Show”(您是否缺少 using 指令或程序集引用?)

但是,当我执行智能感知“转到定义”时,我可以看到那Window是 的子类ContentControl,它是 的子类FrameworkElement,我可以看到Show()方法。

我什至试过System.Windows.Window w = new System.Windows.Window()

这是怎么回事?

编辑:代码示例(如果有帮助):

using System.Windows;

namespace MyApp
{
    public class MainViewModel
    {
        private void SomeMethod()
        {
            Window w = new Window();
            w.Show();
        }
    }
}

编辑 2:“CSProj”项目组:

<ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.ComponentModel.Composition" />
    <Reference Include="System.Data" />
    <Reference Include="System.Windows.Interactivity" />
    <Reference Include="System.Xaml" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
4

0 回答 0